Code: Select all
A$="0"
If Val(A$)
PrintN("Found Value")
Else
PrintN("Is this a bug?")
EndIf
Code: Select all
A$="0"
If Val(A$)
PrintN("Found Value")
Else
PrintN("Is this a bug?")
EndIf
Code: Select all
A$="0"
If Val(A$)=0
Debug ("Found Value")
Else
Debug("Is this a bug?")
EndIf
I'm afraid you're not correct. Val behaves differently if I do this:PB wrote:Your code, as it stands, also fails on PureBasic v4.00 Beta 9 for Windows, but that's because you're not using it correctly. You're supposed to do it like so:
Code: Select all
A$="1"
If Val(A$)
PrintN("Found Value")
Else
PrintN("Is this a bug?")
EndIfCode: Select all
A$="0"
If Val(A$)
PrintN("Found Value")
Else
PrintN("Is this a bug?")
EndIfCode: Select all
A$=(a string that might translate into a number)
If Val(A$) ; something IS a number
Gosub Deal_With_Numbers
Else
Gosub Deal_With_Strings
Endif

Val() is not an IsNumber() function. It just converts a string to a number. And like in most basic dialects, Val("NotANumber") = 0 (not a bug).Alex wrote:If Val can report success turning strings of 1-9 into numbers, it should be able to report success in turning the string "0" into a number.
Alex
yep, and in pb logic 0 = false, and <> 0 = truePB wrote: However, Val doesn't return just True or False, it returns the value of the string.

PB wrote:Your code, as it stands, also fails on PureBasic v4.00 Beta 9 for Windows,
Again, not agree.PB wrote:but that's because you're not using it correctly.
Code: Select all
If 0
Debug "Never show"
EndIf

Code: Select all
A$="0"
If Val(A$)
Debug "this is shown when the 'If' finds a true value (a number that is not 0)"
Else
Debug "this is shown when the 'If' finds a false value (a number equal to 0)"
EndIf
Debug #True
Debug #False
Do I have a fundamental misunderstanding of how "If" operates? When I test, is "If" looking at the true/false result, or the result of the operation? Try the following code:Kale wrote: His code was good code.
Code: Select all
A$="0" If Val(A$) Debug "this is shown when the 'If' finds a true value (a number)" Else Debug "this is shown when the 'If' finds a false value (a number that is not 0)" EndIf Debug #True Debug #False
Code: Select all
A$="9"
If Val(A$)
Debug "this is shown when the 'If' finds a true value (a number)"
Else
Debug "this is shown when the 'If' finds a false value (a number that is not 0)"
EndIf
Debug #True
Debug #FALSE
Debug RESULT=Val(A$)Code: Select all
this is shown when the 'If' finds a true value (a number)
-1
0
9
Code: Select all
this is shown when the 'If' finds a false value (a number that is not 0)
-1
0
0
Maybe I'm unclear on the concept. Shouldn't Val() (or any other operation) return two pieces of information; a true/false value AND a result, and shouldn't "If" look at the true/false value rather than the result?Fred wrote:Val("0") will return 0, which is false in condition.
Code: Select all
A$="0"
If Val(A$)
Debug "this is shown when the 'If' finds a true value (a number that is not 0)"
Else
Debug "this is shown when the 'If' finds a false value (a number equal to 0)"
EndIf
Debug #True
Debug #False
Code: Select all
If OpenWindow(....)
...
Endif
Code: Select all
a = 0;
If a <=0
Debug "oops!"
Else
Debug "meh!"
EndIfCode: Select all
If -1
Debug "this is shown when the 'If' finds a true value (a number)"
Else
Debug "this is shown when the 'If' finds a false value (a number that is not 0)"
EndIf