Re: Checking datatype of CHAR variable in 4GL
Posted in 1998
Ben Knox wrote: > > Does anyone if there a function in Informix 4gl (version 4) which will > let > you check the contents of a CHAR variable to see whether or not it is > a > valid number, without causing a numeric conversion error? > > I have an application which is requesting input from the user, and the > input > can be a number, or a string. This then gets put through a CASE > statement, > more or less as follows: > > DEFINE > var CHAR(5) > > PROMPT "Enter data: " FOR var > > CASE > > WHEN var>=1 AND var<=9999 > DISPLAY "Var is a number" > WHEN var IS NOT NULL > DISPLAY "Var is a string" > END CASE > > The problem I've got is that if the user enters a string, the program > bombs > out with a "Character to numeric conversion error" at the first WHEN > clause. Just use: WHENEVER ANY ERROR CONTINUE LET numeric_var = char_var IF STATUS = -1213 THEN .... it's not a number END IF WHENEVER ANY ERROR STOP .... or the original setting instead of the case statement. > Lastly, does anyone know if there is a "catchall" WHEN statement (like > the * in a UNIX shell CASE statement). Yes. Try OTHERWISE. > Thanks for any suggestions! No problem. Cheers, -- Mark. +----------------------------------------------------------+-----------+ |Mark D. Stock - Informix SA http://www.informix.com |//////// /| |mailto:mdstock@informix.com FAQ http://www.iiug.org |///// / //| | +-----------------------------------+//// / ///| | Tel: +27 11 807 0313 |If it's slow, the users complain. |/// / ////| | Fax: +27 11 807 2594 |If it's fast, the users keep quiet.|// / /////| |Cell: +27 83 250 2325 |Therefore, "No news: travels fast"!|/ ////////| +----------------------+-----------------------------------+-----------+