RE: Integer checks
Posted in 2008
> -----Original Message----- > From: informix-list-bounces@iiug.org [mailto:informix-list- > bounces@iiug.org] On Behalf Of Obnoxio The Clown > Sent: Tuesday, September 16, 2008 1:43 PM > To: informix-list > Subject: Re: Integer checks > > Obnoxio The Clown wrote: > > monkeys paw wrote: > > > >> Hi all, I need an integer to conform to military time, so > >> i have to check that the tens digit is no more than 59, > >> i.e. 2159 is a valid time, 2162 is not. > >> > >> I've not seen much "arithmetic" done in 4gl so could someone > >> suggest the best way to check an int for this condition. > >> > >> > > > > What's wrong with a DATETIME HOUR TO SECOND ? > > > > > > Anyway, no 4GL compiler handy, plus there's all sorts of assumptions here: > > FUNCTION validate_time (lv_time_in) > DEFINE lv_time_in SMALLINT > DEFINE lv_hour, lv_minute SMALLINT > > IF lv_time_in < 0 > THEN > ERROR "Negative time not allowed" > RETURN FALSE > END IF > > LET lv_hour = lv_time_in / 100 > LET lv_minute = lv_time_in - (lv_hour * 100) > > IF lv_hour < 23 > AND lv_minute < 60 > AND lv_minute >= 0 > THEN > RETURN TRUE > ELSE > ERROR "Invalid time" > RETURN FALSE > END IF > > END FUNCTION > Or This: DATABASE sample MAIN DEFINE ok SMALLINT, int_time SMALLINT LET int_time = 567 LET ok = check_time(int_time) DISPLAY ok LET int_time = 1430 LET ok = check_time(int_time) DISPLAY ok END MAIN FUNCTION check_time(in_time) DEFINE in_time SMALLINT, ok SMALLINT, char_time CHAR(4), time_string CHAR(5), this_time DATETIME HOUR TO MINUTE LET ok = TRUE LET char_time = in_time USING "&&&&" LET time_string = char_time[1,2], ":", char_time[3,4] WHENEVER ANY ERROR CONTINUE LET this_time = time_string IF ( STATUS < 0 ) THEN LET ok = FALSE END IF WHENEVER ANY ERROR STOP RETURN ok END FUNCTION > -- > Cheers, > Obnoxio the Clown > > http://obotheclown.blogspot.com > > > > > > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list