[futurebasic] Re: [FB] Font Question (more detail) and Field Question

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2003 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Sun, 5 Jan 2003 02:51:46 -0400
I'm noticing that when one creates an edit
>field, the contents must be text (i.e., not a numeric variable). If I
>put data in a field and then later want to extract it, how do I do
>that? How do I set a variable to the contents of a field? Which also
>leads me to another question ... How do I force the user to only
>enter numeric (including decimals) data?


There is an input filter demo in the Edit Field portion of the Reference
manual I believe (requires appearance runtime).

Here is a FN below that can make sure it is numeric, I think this came from
Jay or similar hackoid professional. ;) I set up a timer in my event loop
to nab the edit field contents and then alert the user or otherwise
re-implant legal values. You can also probably just monitor keypresses and
do it then.

Robert Covington


clear local fn IsNumeric( @strP as ptr )
// return _zTrue if strP points to a number string, else _false
dim as ptr endP
dim ch
dim as boolean isNum,sign,num,base,dot,sci'All init to _false with CLEAR
dim as char decimal
decimal = |[fn IUGetIntl(0)]|

endP = strP + strP.0``

while strP.1`` = _" "
strP ++
wend
while endP.0`` = _" "
endP --
wend
while strP < endP
strP ++
ch = strP.0``
select ch
case decimal
if dot then exit fn else dot = _zTrue
case _"-",_"+"
if sign or base then exit fn else sign = _zTrue
if num and not sci then exit fn
case _"&"
if base or num then exit fn
select strP.1``
case _"h", _"H" : strP++ : base = 16
case _"o", _"O" : strP++ : base = 8
case _"x", _"X" : strP++ : base = 2
case else : base = 16
end select
case < _"0":exit fn
case <= _"9" 'It's a digit!
long if num = 0
long if ch = _"0"
long if ( strP.1`` and 95 ) = _"X"
base = 16 : strP++ : exit select
end if
end if
end if
if base then if ( ch and 15 ) >= base then exit fn
num = num or ch
case else
select ch and 95
case < _"A" : exit fn
case _"E"
long if base = 16
num = num or 14
xelse
if base or sci then exit fn
sci = _zTrue : dot = _zTrue : sign = _false : num = _false
end if
case > _"F" : exit fn
case else'It's a hex digit!
if base < 16 then exit fn
num = num or 63
end select
end select
wend
isNum = num > 0
end fn = isNum