RE: MI-L Testing to ensure a string is numeric

2004-05-19 Thread Jacques Paris
Having been away for few days, I have been fascinated by the thread on the subject seen as a whole. I may have missed important at the onset, something like the string is obtained by a ReadControlValue(). If that was true, then the discussion can go on for a while. But why should it be so? In a

RE: MI-L Testing to ensure a string is numeric

2004-05-19 Thread B. Thoen
On Wed, 19 May 2004, Jacques Paris wrote: Make the user be a little bit more responsible for what he enters, and save the programming for the intelligent parts He who depends on the user to always do the right thing is going to learn that his master work of software engineering will not

RE: MI-L Testing to ensure a string is numeric

2004-05-18 Thread Eric_Blasenheim
Spencer, In terms of speed, I would mostly stick with just the val function. Just the idea that converting a string to a number and back to a string and comparing them is fraught with danger, at least for floating point. Note that the val function returns a number. It returns 0 for things

RE: MI-L Testing to ensure a string is numeric: another approach

2004-05-18 Thread Tim.Nuteson
List, I just wanted to point out another solution from Bill Thoen that seems to be pretty bulletproof: function IsNumeric (byval sVal as string) as logical dim i as integer For i = 1 to Len(sVal) If NOT InStr (1, 0123456789.+-e, mid$(sVal,i,1)) Then 'String contains a

SUM: MI-L Testing to ensure a string is numeric

2004-05-17 Thread Tim.Nuteson
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

Re: SUM: MI-L Testing to ensure a string is numeric

2004-05-17 Thread B. Thoen
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

RE: MI-L Testing to ensure a string is numeric

2004-05-17 Thread Spencer Simpson
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

RE: MI-L Testing to ensure a string is numeric

2004-05-17 Thread Martin Higham
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

RE: MI-L Testing to ensure a string is numeric

2004-05-17 Thread Spencer Simpson
I'm sorry, but Str$(val())is NOT reliable for testing floating-point values. I've been burned by this many, many times, and only use str$(val()) to test integers in very simple applications. In addition to the issue of leading zeroes, there are also issues with: 1. Looking for a - sign at the

Re: MI-L Testing to ensure a string is numeric (An unortodox way)

2004-05-17 Thread Soporte
Why don't you try something like this: Declare Sub Main Sub Main() Dim a as string OnError Goto LocalError a = a / 1 Exit sub LocalError: If Err() = 306 Then Note a is not numeric End If End Sub - Original Message - From:

FW: MI-L Testing to ensure a string is numeric (An unortodox way)

2004-05-17 Thread Spencer Simpson
-Original Message- From: Spencer Simpson [mailto:[EMAIL PROTECTED] Sent: Monday, May 17, 2004 2:06 PM To: 'Soporte' Subject: RE: MI-L Testing to ensure a string is numeric (An unortodox way) I don't know which version of MapBasic you're using. In the version I use (5.0) this produces

MI-L Testing to ensure a string is numeric

2004-05-13 Thread Tim.Nuteson
Listers, Does anyone have a method using MapBasic to test whether a string is numeric? I have a dialog with an edittext box that needs a numeric input. Even if the solution is just a big hack that would be OK, since I am going to make a logical MB function along the lines of IsNumeric(123) =

RE: MI-L Testing to ensure a string is numeric

2004-05-13 Thread Cummings, Mike
Below is a function that I wrote to get the North/South footage(123) out of a string with a format of: Fr SE corner 123N 654W. Function strpnsft(ByVal s1 As String) As integer Dim fr, n, s, a As Integer dim s2 as string s2=ucase$(s1) fr = InStr(1, s2, FR ) + 5 n = InStr(fr, s2, N) - 1 s =

Re: MI-L Testing to ensure a string is numeric

2004-05-13 Thread Robert Crossley
A quick one would be: Code... If IsNumeric(x) Then do something knowing that it is a number Else do something else because it isn't a number End If More Code... Function IsNumeric(ByVal sTestStr as String) As Logical If Str$(Val(STestStr)) = sTestStr Then IsNumeric =