It's not necessarily a fault depending upon the use required of the function. I've just run my 26 year old copy of GW-Basic and in that Val behaves as dfallen indicated as it also does in my copy of QuickBasic 4.5.Returning zero as a fault condition is not very helpful
VAL had other "features" as well. For one, it would strip out spaces, linefeeds, and tabs. So, for example, VAL("12 34") woud return 1234.
One good thing is that it would recognize &H and &O as hex or octal numbers.
The bad news is that it only recognized the the period as the decimal separator so it was not useful in international applications.
As I recall, I had a custom VAL function that I used in my aplications. Not hard to code and it did what I wanted the way I wanted it done. When speed was important, I would code it in assembler. Of course, that was in the pre-Windows era and processors were slow. I have no inclination to program in assembler under Windows.
Sub VAL(s)
temp = ""
temp2=0
flag = 0
If StrLength(s) = 0 Then
Return 0
Else
len = StrLength(s)
For a = 0 To len -1
If IsNumber(StrAt(s,a)) Then
temp = temp & StrAt(s,a)
Else
If StrAt(s,a) = "." Then
If flag = 0 Then
flag = 1
temp = temp & "."
End If
End If
End If
Next
If temp = "" OR temp = "." Then
Return 0
Else
temp2 = temp2 + temp
Return temp2
End If
End If
End Sub
As Basic4ppc is untyped, or more accurately does automatic type conversion, a numeric string is treated the same a numeric literal so Val is not needed in this case.See how the computation is treating the string "18" as the value 18.
As Basic4ppc is untyped, or more accurately does automatic type conversion, a numeric string is treated the same a numeric literal so Val is not needed in this case.
If headingDirection = 360 Then headingDirection = 0
Yes, I'm afraid that the Basic4ppc rule for logical comparisons is not documented but it seems that all comparisons are made as strings and typed variables are converted to a string for the comparison.What was in my head was that Basic4PPC would convert to numeric for the comparison but it doesn't and finds that "360.0" is not equal to 360.
Int or Abs would work in your situation.I would have used a Val() if Basic4PPC had one.
'S = String to be checked for a number ...