Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to force a field to be an INTEGER in form ?

Status
Not open for further replies.

ziguy

Programmer
May 13, 2004
4
FR
Hello everybody,

I've got one more problem.
it's in a form (a screen) :
the probleme is simple : at the beginnig we used a column which was an integer so in the screen we can only enter 10 or 15 or 1000 but never 10.12 15.89 etc.. using this line :

f026 = TOTO.qte_disp, AUTONEXT, COMMENTS = "Number ?"

but the table structure have been modify and this column (qte_disp) is now a decimal 7.2.
So in the screen it is now possible to entre 10.12 15.55 etc.
So I would like to know if it's possible to block people entering decimal value.


I used this :

f026 = TOTO.qte_disp TYPE SMALLINT, AUTONEXT, FORMAT="###" , INCLUDE (0 to 999), COMMENTS = "Number ?"
now We cannot enter decimal value bye validate with enter key. But if we used arrow key we can enter decimal value even if the screen show an integer value.

So if you understand me, could you help me ? thank a lot
 
Hi,

Relying on table.column concept may not suit, as the properties of the object will be derived to the form. Instead use the imaginary or pseudo table FORMONLY in this case as below:

f026 = formonly.bene_qty TYPE smallint, AUTONEXT, FORMAT="###", INCLUDE = (0 to 999), COMMENTS = "Whole Numbers only, Fractions are not allowed." ;

With the above attribute fractional value input would be reported as "Error in field"

Regards,
Shriyan
 
If the above doesn't sort the problem, then you could get it entered as text and use the following function to check if it's a number:

#------------------------------------------------------------------------------
# Takes a string and works out whether it's a number or not...
FUNCTION isdigit4gl(p_string,p_check_float)
DEFINE p_string CHAR(100), # Doubt anyone would want to check whether
# a string of length greater than 100 is a
# number or not...
p_check_float SMALLINT # Are we checking a float?
DEFINE i,j,success INTEGER,
l_decimal_point SMALLINT

LET success = TRUE
LET l_decimal_point = FALSE

LET p_string = p_string CLIPPED
LET j = LENGTH(p_string)
IF j = 0 THEN
RETURN FALSE # is a string of length 0 a number? i.e. is "" a number.
# I'm assuming here it's not
END IF

FOR i = 1 TO j
IF NOT (p_string MATCHES "[0123456789]" ) THEN
IF i = 1 AND p_string = "-" THEN
# It's just a negative number..
ELSE
IF p_check_float THEN
IF p_string = "." AND l_decimal_point = FALSE THEN
# It's just a decimal point - but make sure there
# aren't two decimal points in it...
LET l_decimal_point = TRUE
ELSE
LET success = FALSE
EXIT FOR
END IF
ELSE
LET success = FALSE
EXIT FOR
END IF
END IF
END IF
END FOR

RETURN success

END FUNCTION
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top