Using Apex Validation on Text Fields? - oracle

I'm having an issue getting my validations to work correctly in Apex.
I have 3 page items that are causing me trouble, :P5_JACKPOT, :P5_TICKET_PRIZE, :P5_TOTAL_PRIZE. Jackpot can be any size, and ticket_prize + total_prize can be any size as long as they are LESS then jackpot. The validations I have in place for this are as follows:
if :P5_TICKET_PRIZE > :P5_JACKPOT then
return false;
else
return true;
end if;
Same validation for both items, with the necessary replacements, simple enough. The issue is, it doesn't seem to work for all numbers. For example, having a jackpot value of 200, and 50 for both other items cause the error to flag, when it shouldn't. However, having a jackpot value of 200, and other values of 100 + 100 don't cause the error flag, as it should. It seems that some numbers work, and others don't. Is there any reason why this is?

It sounds like the problem is one of data typing. :P5_TICKET_PRIZE and :P5_JACKPOT are both strings so when you compare them, you get character comparison semantics. Alphabetically, the string "50" comes after the string "200" since the character "5" comes after the character "2". If you want to compare the numeric value in :P5_TICKET_PRIZE to the numeric value in:P5_JACKPOT, you'd need to apply a to_number function to both sides of the expression
if to_number( :P5_TICKET_PRIZE ) > to_number( :P5_JACKPOT ) then
return false;
else
return true;
end if;

Related

Oracle Apex Checkbox Group Limit

This might be a silly one but haven't been able to figure it out.
I have a Checkbox Group Item (with Static info) with 4 different options, I want to limit the amount of checked boxes to just two. Is this something possible to make?
Thank you
A checkbox is submitted as a colon-separated string. APEX_STRING has lots of functionality to convert the string to a pl/sql collection (and back). Once converted you can use functions like FIRST, LAST, COUNT. Or even compare collections using INTERSECT. For checking a max nr, a COUNT is enough.
So the validation would be something like this (type Function Body returning Error Text):
DECLARE
l_arr apex_t_varchar2;
BEGIN
l_arr := apex_string.split(:P13_CHECKBOX,':');
IF l_arr.COUNT > 2 THEN
RETURN 'Can only select 2 values';
ELSE
RETURN NULL;
END IF;
END;

Can an array of strings of size 1 be used like a string?

I'm translating a program from asp to asp.net. The creator has a few function that I'm scratching my head over. It seems to be passing back arrays but the results of the function are used as if they're strings in some situations and arrays in others.
Mostly it operates as if it returns a string but sometimes it'll do for each on the result which indicates that it's actually an array of strings. I've searched the web to see if there's some weird corner case logic but nothing specific to this comes up.
function textvalue(myPar)
{
eval("var anotherArray=" + myPar);
anotherArray.sort();
if (eval("datatype" + myPar)=="datetime")
{
//if (eval(myPar)==null || eval(myPar)=="null" || eval(myPar)=="")
if (anotherArray.toString()==null || anotherArray.toString()=="null" || anotherArray.toString()=="")
{
return anotherArray;
}
else
{
return new Array(convertFromAODdatetime(anotherArray.toString()));
}
}
else
{
return anotherArray;
}
}
USE 1
Response.Write(...existing status: " & theStructure.textvalue("structureItemStatus") & "....")
USE 2
For Each datum In fileData.textValue("fileNomenclature")
Response.Write(...
I'm ultimately wondering if I need to do something unique w/ these functions or maybe the resulting datatype to replicate the logic of the function properly.
I don't believe that an array works that way. You might be able to replace the array with a list and it work more in the way you are expecting.
Another option is to just run an if statement to see if the array length is greater than 1 then run a foreach loop otherwise just grab arry[0].

Populating a TDBTest box Delphi XE2

So, what I am trying to accomplish is when the number in one field is >= to a certain number then the field I want to populate will do a comparison and populate, or not depending on the condition. If the result is true the field is populated fine, but if the result is false it still performs the calculation and populates the field with " -4. I have worked trying to fix the problem for over a week. Can't seem to get it done. My variable 'total' is declared an integer.
I understand that I am comparing text and integers and that I should not compare that way and that I should convert the text to integer then calculate, but every time I try to convert something to integer I get an error code telling me that it is not a valid integer. I don't have enough experience to figure this out.
I am creating a four week budget. I buy an item, calculate how many portions there are and spread the cost through the four weeks. If there are more portions than 4 what is left over after the four week that number is calculated and automatically entered in the "leftover" field. In this code everything works perfectly, except the last if statement.It calculates and enters the data correctly, if the portions are more than 4. If they are less than 4 it writes a"-4" in the field. I cannot see my error. That is where I need help.
My Code:
procedure TForm1.costperChange(Sender: TObject);
var
Total: integer;
total1: double;
begin
Total1 := tblCosts.FieldByName('Cost').Asfloat / tblCosts.FieldByName('servings').Asfloat ;
costper.Text:= floattostr(total1);
if serv.Text >= '1' then
wk1.Text:= costper.Text
else
wk1.Text:= '';
if serv.Text >= '2' then
wk2.Text:= costper.Text
else
wk2.Text:= '';
if serv.Text >= '3' then
wk3.Text:= costper.Text
else
wk3.Text:= '';
if serv.Text >= '4' then
wk4.Text:= costper.Text
else
wk4.Text:= '';
if serv.Text >= '5' then
total:= strtoint(serv.Text);
total:= total - 4;
left.Text:= inttostr(total);
end;

oracle apex - how to validate name length with a value

I'm tring to validate whether the name length is met with the required value or not.
I made a code but it works in a bad way
I'm trying to see the entered name whether is less then 3 or not and return a Boolean to print the message or not.
in some cases the code prevent any entered date and the other is saving the data even if it's less then 3 .
my code is
if length(':P11_first_name') < 3 then
return true;
else
return false;
end if;
what I need to do to solve this problem.
Don't put the item name in single quotes. You're checking whether the literal string ":P11_first_name" has a length less than 3. That string will always be exactly 14 characters. You want
if length( :p11_first_name ) < 3
then
return true;
else
return false;
end if;

What makes Crystal ignore record selection formula?

Crystal 2008. Have record selection formula ending with
and
( ( "Zero" in {?Credit_Debit} and {V_ARHB_BKT_AGING_DETAIL.AMOUNT} = 0)
or ( "Credit" in {?Credit_Debit} and {V_ARHB_BKT_AGING_DETAIL.AMOUNT} < 0)
or ( "Debit" in {?Credit_Debit} and {V_ARHB_BKT_AGING_DETAIL.AMOUNT} > 0) )
but no matter what combination of values is selected for Credit_Debit the result set is the same.
Also without success, I tried joining the parameter array into a single string and using lines like
or ( {#Cred_Deb_Choices} like "*Credit*" and {V_ARHB_BKT_AGING_DETAIL.AMOUNT} < 0)
Using the first method works in the same formula when the parameter values are integers, as:
and ({?Location ID} = 0 or {V_ARHB_BKT_AGING_DETAIL.LOC_ID} in {?Location ID})
I examined the generated SQL, and saw that the part at the beginning that had no effect was not shown.
I changed a part that tested for a hard-coded value to instead test for a parameter value, and looked at the SQL again. No change.
When you try to create a filter that doesn't fit with the datatype of the field then that doesn't get reflected in record selection formula.
For Integer field give integers in record selection for text give text.
E.g:
ID=0 and Name='XXX' works
ID='Zero' and Name='XXX' doesn't
This should solve your issue

Resources