Home » Developer & Programmer » Forms » numeric error return date
numeric error return date [message #626954] Wed, 05 November 2014 09:26 Go to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi all,

I made a package contains functions and procedures which the control over the data entered by the user and I want that when the user enter the field not valid an alert data is displayed showing the example eurreur user enter a date in numeric fields
FUNCTION Valid_date (p_string IN VARCHAR2, 
                     p_format IN VARCHAR2 DEFAULT 'dd/mm/yyyy') 
RETURN DATE 
IS 
  v_return DATE; 
  k        VARCHAR2(200) := 'use date'; 
  al       ALERT; 
  alrt     PLS_INTEGER; 
BEGIN 
    al := Find_alert('TEST_DATE'); 

    IF NOT Id_null(al) THEN 
      Set_alert_property(al, title, 'use dates'); 

      Set_alert_property(al, alert_message_text, 'fuse date'); 
    -- alrt :=show_alert('TEST_CHAR'); 
    ELSE 
      Message('alert is null'); 

      Message('alert is null'); 

      RAISE form_trigger_failure; 
    END IF; 

    v_return := To_date(p_string, p_format); 

    RETURN v_return; 
EXCEPTION 
  WHEN OTHERS THEN 
             alrt := Show_alert('TEST_DATE'); 
             RAISE form_trigger_failure; 
END valid_date; 
Re: numeric error return date [message #626956 is a reply to message #626954] Wed, 05 November 2014 09:40 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Considering that forms lets you set text items as being date datatype, why have you written any of this code?
Re: numeric error return date [message #627184 is a reply to message #626956] Sat, 08 November 2014 06:14 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi cookiemonster ,sorry for the late reply..
I want to display an alert when user enter a letter in the following trriger (key_next_item and post_text_item), I made this code but an alert appears SEVERAL times successively

my code for validate filed in number
 PROCEDURE ptunel (a VARCHAR2 )
IS
  --k varchar2(30):='user number';
  al ALERT;
  alrt PLS_INTEGER;
  --show_alert('TEST_NUMBER');
  -- alrt :=show_alert('TEST_CHAR');
BEGIN
  al:=Find_alert('TEST_NUMBER');
  IF NOT Id_null(al) THEN
    Set_alert_property(al,title,'use number');
    Set_alert_property(al,alert_message_text,'enter the number');
    -- alrt :=show_alert('TEST_CHAR');
  ELSE
    Message('alert is null ');
    Message('alert is null ');
    RAISE form_trigger_failure;
  END IF;
  FOR i IN 1..Length(a)
  LOOP
    IF NOT
      (
        (
          Ascii(Substr(a,i,1))>=48
        )
        AND
        (
          Ascii(Substr(a,i,1))<=57
        )
      )
      THEN
      alrt:=Show_alert('TEST_NUMBER');
    END IF;
  END LOOP;
END ptunel ;
chat conversation
END 

Re: numeric error return date [message #627187 is a reply to message #627184] Sat, 08 November 2014 08:30 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
To paraphrase Cookiemonster, considering that forms lets you set text items as being number datatype, why have you written any of this code?
Re: numeric error return date [message #627199 is a reply to message #627187] Sat, 08 November 2014 14:43 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
NO NO NO Dear @mist598 its very very easy way to handle, Have you solved your problem i ahve created .FMB file for you see in image


Regard
Mughal
Re: numeric error return date [message #627204 is a reply to message #627199] Sun, 09 November 2014 01:52 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Quote:
Have you solved your problem

no, what should i do ? you mean change the datatype of field right?

Re: numeric error return date [message #627213 is a reply to message #627204] Sun, 09 November 2014 06:11 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
No just create one parameter Name "PREV_LEN" in property, Parameter data type 'Number' and maximum length '0'

and form level

when-new-forms-instance

Begin
   :Parameter.prev_len := Null;
   
End;

when-timer-expired

Declare
   curr_len Number;
   timer_str TIMER;
   chr_to_asc Number;
   entered_val char;
   
Begin
	
	 	   curr_len := Length(:enter_num);
	 	   
	 	   If curr_len > :Parameter.prev_len or curr_len = 1 Then
	 	        Select substr(:enter_num,-1,1) into entered_val from dual;
	 	        Select ascii(entered_val) into chr_to_asc from dual;
	 	        
	 	        If chr_to_asc Not Between 48 and 57 Then
	 	   	          If Show_Alert('ALR') = Alert_Button1 Then
	 	   	          	   Null;
	 	   	          End If;	   
	                :enter_num := Substr(:enter_num,1,length(:enter_num)-1);
	 	        End If;	    
	 	        
	 	   End If;
	 	   
	     :Parameter.prev_len := curr_len;
	     timer_str := Create_Timer('timer_textitm_num', 50, No_Repeat);
	 	   
End;	 


create one Alert Name "ALR" in property message type "Characters Not Allowed" Alert style "Stop"

and BLOCK LEVEL Create text item suppose "Enter_num" in property data type "char"

TRIGGERS

PRE-TEXT-ITEM

Declare
	timer_str TIMER;

Begin
	
	 timer_str := Find_Timer('timer_textitm_num');
	 If Id_Null(timer_str) Then
	     timer_str := Create_Timer('timer_textitm_num', 50, No_Repeat);
	 End If;    
	 
End;	 

TRIGGER

POST-TEXT-ITEM

Begin
	 Delete_Timer('timer_textitm_num');
End;



Now enjoy code i have posted for those who have not installed FORM Developer in their pc's anywayz
download this TESTED fmb file

Regards
Mughal

[Updated on: Sun, 09 November 2014 06:30]

Report message to a moderator

Re: numeric error return date [message #627222 is a reply to message #627213] Sun, 09 November 2014 09:21 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Maybe I'm wrong, but the whole discussion is simply pointless.
Re: numeric error return date [message #627254 is a reply to message #627222] Mon, 10 November 2014 03:06 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Indeed, there's no need to write any code at all since forms will tell you if what you're entering is the wrong format.
But if you are going you write code you must use when-validate-item. If you use anything else then you can't stop the user from saving the record with the incorrect data.
Timer's do not exist to do validation.
Re: numeric error return date [message #627258 is a reply to message #627254] Mon, 10 November 2014 03:46 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
Problem is need to fulfilled the requirement of the users on this forum according to their requirement those who are asking the questions YES You are also right that data type "NUMERIC" is ok i am not saying that you are wrong his requirement was as i have provided the solution as far as concern timer i think you did not tested this code properly you can't move the cursor untill unless you will not enter the correct data. Hope you will understand.


Regards
Mughal



Re: numeric error return date [message #627260 is a reply to message #627258] Mon, 10 November 2014 03:56 Go to previous messageGo to next message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
I am sorry you are Seniors I am still learning from this forum like you peoples I accepted you are right.


Regards
Mughals
Re: numeric error return date [message #627268 is a reply to message #627260] Mon, 10 November 2014 04:47 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Ok - your timer is carefully constructed to restart itself constantly, but I personally wouldn't want to waste resources on that (since once started it'll keep going till the form is shut down). And it removes invalid characters (I missed that bit initially)
There are problems though:
1) You've set it to check the last character entered after every 50ms. If the user enters 2 characters in 50ms (theoretically possible, especially if the user jams a key down) then one of the characters won't be checked.
2) Your code assumes the number must be a positive integer, with no thousand seperators. A minus sign, a dot or a comma will all cause an error and they are valid in numbers. And of course if you query a value from the DB it can contain all of those. (And yes, the OPs example above has the same mistake).

The simplest and safest way to see if a string is a valid number is to use to_number on it and see if it works.
The safest way to make sure a item in forms is the correct datatype is set it to the correct datatype in the first place.

And I stand by the never use timer for validation comment. Validate triggers can ensure bad data can not be saved, the whole architecture of forms ensures it, if you use any other method you open up the posibility of holes that allow bad data to get through.
Re: numeric error return date [message #627318 is a reply to message #627268] Mon, 10 November 2014 16:19 Go to previous message
CraigB
Messages: 386
Registered: August 2014
Location: Utah, USA
Senior Member
Quote:
I made this code but an alert appears SEVERAL times successively

Yes, your code has the possibility to display multiple Alerts because you are calling your Alert inside of your LOOP and you are not terminating your loop if you display the Alert.
Quote:
I want to display an alert when user enter a letter in the following trriger (key_next_item and post_text_item)...

This really is the wrong place to put "Validation" logic - you should use a When-Validate-Item trigger instead.

Furthermore, you forum posting is confusing. First you post a Function definition that takes VARCHAR2 parameters but then you say in your next post that if the user enters a CHARACTER you want an error. So, should the user enter a Date using DD/MM/YYYY format where DD = 0-9, MM = 0-9, and YYYY = 0-9? If this is correct, then why would your validation function accept VARCHAR's for the date? This is very confusing...I agree with CookieMonster and LittleFoot - if you want a DATE only, then set the field data type to DATE and if the date can only be entered in a specific format, put this format in the Format Mask property. Problem solved.

Craig...
Previous Topic: How to export Data to excel
Next Topic: certain form problem
Goto Forum:
  


Current Time: Fri Apr 26 06:44:12 CDT 2024