No - str$(val("1.2345")) returns "1.2345".

Where it may fall down, is in the use of thousands separators.  For this you
should use
str$(val(DeformatNumber$("10,001"))).

With this, it will be robust, but you may want to check for and strip
leading zeroes (as Bill highlights).

Best Regards,

Martin Higham
Avantra Geosystems

ph (61 3) 8504 0428   0425-730-428
fx (61 3) 9596 7997
www.avantra.com.au




> -----Original Message-----
> From: Spencer Simpson [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, 18 May 2004 01:55
> To: [EMAIL PROTECTED]
> Subject: RE: MI-L Testing to ensure a string is numeric
>
>
> No, it will notThere are a couple of ways to implement them, some of which
> are more efficient than others.
>
> The str$(val()) method is the fastest method, but it's not the
> most robust.
> For one thing, it works only for integers.  However, it's great for quick
> applications that require only integers.
>
> For robust, idiot-proof applications, you need more sophisticated
> validation
> routines.
>
> It is possible, of course, to write a routine that scans the string
> for the correct format, but this can be very slow, given that you
> have to make calls to mid$() for every character in the string.  If
> you've been programming for any length of time, you've probably written
> one that you can adapt to MapBasic.  Or you can write one in a faster
> language, put it in a DLL, and link to it from MapBasic (scanf is NOT
> recommended).
>
> Another method is to try assigning the string to a MapBasic
> window variable,
> and catching any errors. This method is optimal for validating
> strings that
> can take non-integer values.
>
> run command "Dim v_dbl as float"
> ...
> function good_float (ByVal s as string, f as float) as logical
> On Error Goto notvalid
> run command "v_dbl="+sval
> OnError goto 0
> f=val(Sval)
> good_float = true
> exit function
> notvalid: resume failure
> failure:  good_float = false
> end function
>
>
> Hope this helps
> Spencer
>
>
>
> -----Original Message-----
> From: B. Thoen [mailto:[EMAIL PROTECTED]
> Sent: Monday, May 17, 2004 11:05 AM
> To: Tim.Nuteson
> Cc: [EMAIL PROTECTED]
> Subject: Re: SUM: MI-L Testing to ensure a string is numeric
>
> Would that algorithm return the correct result if you fed it a numeric
> string like '0023456', or are numbers with leading zeros not going to be
> encountered?
>
>
> On Mon, 17 May 2004, Tim.Nuteson wrote:
>
> > Thanks to all who responded to my question:  How can I ensure that a
> > value entered into an EditText control of a MB dialog is numeric?  The
> > simplest solution was offered by Michael Taylor, Martin Highham, and
> > Robert Crossley:
> >
> >     If str$(val(teststring)) = teststring then
> >       'numeric
> >     Else
> >       'not
> >     End If
> >
> > Thanks again,
> >
> > Tim Nuteson
> > Target
> >
> >
> > ---------------------------------------------------------------------
> > List hosting provided by Directions Magazine | www.directionsmag.com |
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > Message number: 11784
> >
>
>
> ---------------------------------------------------------------------
> List hosting provided by Directions Magazine | www.directionsmag.com |
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> Message number: 11788
>
>
>
> ---------------------------------------------------------------------
> List hosting provided by Directions Magazine | www.directionsmag.com |
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> Message number: 11789
>


---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 11793

Reply via email to