How to test for a number

MisterX b.xavier at internet.lu
Wed Mar 16 12:17:48 EST 2005


Sorry for coming in late in the test discussion...

My approach to this was to eleminate doubts 
regarding what format it was...

I've had many different occasions for this testing and
for lots of different log outputs from dos, emc tools,
copy tools, reskit tools, etc...

They all use different formats, exceptions, etc...

But in general it comes down to this...
<untested of the top of my head ;)>
function isanumber mynumber
  put char 2 of 3/2 into mydecimaldelimiter -- get the decimal

  -- eliminate thousands separators and other human crap

  if mydecimaldelimiter is comma then
    replace "." with "" in mynumber
  else
    replace "," with "" in mynumber
  end if
  put "'" into humancrap -- just one example of... ;)
  repeat for each char c in humancrap
    replace c with "" in mynumber
  end repeat
  get mynumber is a number 
  return it
end isanumber

or

much simpler... and to avoid errors in handlers/functions
without a slower check if mynumber isanumber...
<also untested ;>
try
  get mathop(mynumber)
catch oops
  return "err:"&&oops -- or return 0, -1 or NAN or 
  -- whatever fruity human crap ;)
finally
return it
end try

OK, this is just for text. Styled text recognition would
have to be smarter...

I dont like registry checking because it's bound to change from
one windows version to the other.

Maybe an easier script would be to call a vbs script...
But im still trying to find an easy method to call them from
runrev... 

XOS has many testing routines for this to prevent human crap from
happening in the system's routines! ;)

Type of number/date/format checking, character, word, etc...

But it's not coming out very soon but at least there you have 
my basic laws of number checking ;)

cheers
Xavier


> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com 
> [mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of 
> Thierry Arbellot
> Sent: Wednesday, March 16, 2005 17:37
> To: How to use Revolution
> Subject: Re: How to test for a number
> 
> On 2005, Mar 16, , at 17:28, Klaus Major wrote:
> 
> > Hi Jonathan,
> >
> >> Well, that brings up a possibility...
> >>
> >> Shouldn't there be a way to check for the system settings 
> (perhaps in 
> >> the registry) and adjust for that in the script?
> >
> > sounds good :-)
> >
> > Any hints on how to do this on win and a mac?
> >
> >
> > Regards
> >
> > Klaus Major
> > klaus at major-k.de
> > http://www.major-k.de
> >
> 
> some hints to get the local decimal separator
> 
> MacOS
> 
>      do "get item 2 of (1.1 as string)" as appleScript
>      put the result into theDecimalSeparator
>      replace quote with empty in theDecimalSeparator
> 
> Windows 2000/XP
> 
>      put queryRegistry("HKEY_CURRENT_USER\Control
> Panel\International\sMonDecimalSep") into theDecimalSeparator
> 
> Thierry
> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 



More information about the use-livecode mailing list