Check date value in 4gl
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
How can i check the date value to make sure the user entered something into a form. For instance, the following does not work... input by name d1 after field d1 if (length(d1) == 0) then next field d1 end if thanks!! -- original guitar music at http://www.mindspring.com/~nlymbo
steveFarris wrote: > > How can i check the date value to make sure the user entered something > into a form. For instance, the following does not work... > > input by name d1 > > after field d1 > if (length(d1) == 0) then if length(dl) = 0 then ^ > next field d1 > end if > > thanks!! Art S. Kagel
steveFarris wrote: > How can i check the date value to make sure the user entered something > into a form. For instance, the following does not work... > > input by name d1 > > after field d1 > if (length(d1) == 0) then > next field d1 > end if Art questioned the use of '=='; it actually is supported in I4GL, and IIRC it is a synonym for '=', so that the truly perverse can write: LET d1 == MDY(8,7,2000) One general answer is the REQUIRED attribute. However, this is not checked in the AFTER FIELD clause; it is checked when the ACCEPT key is pressed. You can insist that the user enters a date by checking whether the date value is not NULL in the AFTER FIELD clause: AFTER FIELD d1 IF d1 IS NULL THEN NEXT FIELD d1 END IF If the type of d1 is DATE, then the user must enter a valid value or leave the field blank. You can also play funny tricks with PICTURE and DEFAULT such that the user cannot leave the field blank. If you need to range check the date (and few date fields in a form are completely unconstrained within the range 0001-01-01 to 9999-12-31), then the IS NULL test is probably as simple as any. Note that LENGTH is normally applied to string variables. I'm not sure what happens if you pass a DATE to it. I'd expect that it would convert the DATE value to a string, and the LENGTH of the null date would be zero, but it isn't the direct way of checking that the value is not null. -- Yours, Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h> Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN "I don't suffer from insanity; I enjoy every minute of it!"
Jonathan Leffler wrote in message <398F3C30.BC46923@informix.com>... >Note that LENGTH is normally applied to string variables. I'm not sure >what happens if you pass a DATE to it. I'd expect that it would convert >the DATE value to a string, and the LENGTH of the null date would be >zero, but it isn't the direct way of checking that the value is not >null. > It is converted to a string but the length of a null date is undefined length(undefined) = undefined hence I would expect it to give null. FUNCTION FN_is_empty(x) DEFINE x CHAR(200) IF (LENGTH(x CLIPPED) == 0) OR (x is null) RETURN TRUE ELSE RETURN FALSE END IF David Williams (FAQ at www.smooth1.demon.co.uk) >-- >Yours, >Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h> >Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN > "I don't suffer from insanity; I enjoy every minute of it!"
smooth1 wrote: > Jonathan Leffler wrote in message <398F3C30.BC46923@informix.com>... > >Note that LENGTH is normally applied to string variables. I'm not sure > >what happens if you pass a DATE to it. I'd expect that it would convert > >the DATE value to a string, and the LENGTH of the null date would be > >zero [...] > > It is converted to a string but the length of a null date is undefined > > length(undefined) = undefined > > hence I would expect it to give null. Yes; sounds very plausible -- it's amazing what I can forget in the heat of the moment. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN #include <disclaimer.h>