Re: Converting string to numerical data - regardless of errors
Posted in 1994
In article <39bniu$kci@emory.mathcs.emory.edu>, kestnb!mdk@uunet.uu.net (Michael Kastler) wrote: Regarding checking if a string is numeric: > variable crashes the program. I really, really don't want to turn on > error trapping for the program - does anyone know of any way to check > if specific data is numerical or text or a way to convert any text to a > form that is handleable by an integer variable (such as turning all > text into 0's or even their ascii codes would be acceptable)? You don't have to remove error handling for long! I have a common routine that looks something like this (off the top of my head you understand): FUNCTION is_number(l_text) DEFINE l_text CHAR(50) # Cope with looong numbers! WHENEVER ANY ERROR CONTINUE LET l_text = l_text + 0 WHENEVER ANY ERROR STOP # Or call you favorite error handling routine IF status != 0 THEN RETURN FALSE END IF RETURN TRUE END FUNCTION I've built quite a collection of these type of routines, which live pre-compiled in a special little directory. At compile time I just "link" in the appropriate .4go and everything works like magic. Don't even see the code. Encapsualisation I think the OOPers call it? Regards, Kerry S --------------------------------------,------------------------------------- Kerry Sainsbury, kerry@kcbbs.gen.nz | THE INFORMIX FAQ Quanta Systems, Auckland, New Zealand | kcbbs.gen.nz:/informix/* | mathcs.emory.edu:/pub/informix/faq/* +64 9 377-4473 (work) 276-5546 (home) | quasar.ucar.edu:/?