RE: Char to Integer
Posted in 2004
Try this (you appear to be using 4gl): The ok is so that you can distinguish between an invalid string ie: "" or "JDFKL", etc. and a string that contains "0". You could make it fancier, if you want it to deal with commas. If you want integers only, change the data type of out_num and drop the "." part of the IF statement. CALL chk_char(my_string) RETURNING ok, my_num ... FUNCTION chk_char(in_string) DEFINE in_string CHAR(100), t SMALLINT, out_num DEC(16), out_flag SMALLINT LET out_flag = TRUE IF ( LENGTH(in_string = 0 ) THEN RETURN FALSE, 0 END IF FOR t = 1 TO LENGTH(in_string) IF (( in_string[t] > "9" OR in_string[t] < "0" ) AND ( in_string[t] <> "." )) THEN LET out_flag = FALSE LET out_num = 0 EXIT FOR END FOR END FOR IF ( out_flag = FALSE ) THEN RETURN out_flag, out_num END IF LET out_num = in_string RETURN out_flag, out_num END FUNCTION --EEM -----Original Message----- From: navdeep virk [mailto:nvirk@msn.com] Sent: Monday, March 08, 2004 4:22 PM To: informix-list@iiug.org Subject: Char to Integer List , I am storing a string variable (which can be integer or alpha ) into an integer variable to check for alpha character's in the string variable. The process works fine as I check whether the integer is null after the assignment ( that is the assigment succeeds or not). null means it could not convert the string to integer . The Problem is that if the assignment fails it generates a error code -1213 in the error log , which is not desirable . I am using "WHENEVER ERROR CONTINUE" earlier on in the code. I want to turn of wrror logging only for this condition . Is there a way I can suppress this benign error from being written to the error log .Pl suggest any other function to check for aplha characters in a string apart from scanning the whole string and exiting when an alpha character is found . rgds, NSV _________________________________________________________________ Fast. Reliable. Get MSN 9 Dial-up - 3 months for the price of 1! (Limited-time Offer) http://click.atdmt.com/AVE/go/onm00200361ave/direct/01/ sending to informix-list sending to informix-list