Testing for numeric input
Darren Reely
darren.reely@latticesemi.com
Tue, 18 May 2004 16:35:40 -0700
Martyn,
Take a look at this hack. Its rough but I think it performs you
requested function.
screen test-num
temp t_char varchar*7
define d_num float = nconvert(t_char); + (d_denum/100) ;&
title "test-num" centered
skip 4
field t_char label "testnum" pattern
"((A|B|C|D|E|F|G|H)|(+|-)<(#)>.<#<#<)" upshift
field d_num label "rnum" picture " ^^^.^^" output scale 2 leading '-'
display
procedure edit t_char
begin
if 'A' <= fieldtext[1:1] and 'H' >= fieldtext[1:1]
then warn = 'Letter ' + fieldtext + ' entered.'
if '+' = fieldtext[1:1] or '-' = fieldtext[1:1] or ('0' <=
fieldtext[1:1] and '9' >= fieldtext[1:1])
then if d_num < -999.99 or d_num > 999.99
then error "Number out of range."
else warn = 'number = ' + formatnumber(d_num,"
###.##","-###.##"," 0.00") ;&
end
Darren
Thomson, Martyn EDUC:EX wrote:
> -----Original Message-----
> From: Thomson, Martyn EDUC:EX [mailto:Martyn.Thomson@gems1.gov.bc.ca]
> Sent: Tuesday, May 18, 2004 4:24 PM
> To: POWERHOUSE NEW (E-mail)
> Subject: Testing for numeric input
>
> Hello listers,
> Does anyone know of a simple way to test if the input to a text
> field is numeric within a range -999.99 to +999.99 with the "+"
> being optional.
> Using NCONVERT(fieldtext) causes a data expression error when the
> argument is not numeric.
> I looked at matching against every possible pattern the user could
> enter, but since the "-","+" and "." are optional on input, and
> the range has be taken into account, the number of combinations
> soon gets unmanageable.
> I could loop through each character matching against characters 0
> to 9 , . - + but then coding to ensure that the plus, negative
> and period characters are in appropriate positions and not
> repeated, also soon becomes lengthy.
> There must be a more elegant method eh?
>
> Regards,
> Martyn Thomson
> Ministry of Education, Victoria, BC
>
>
>
>