Val() Problems
Val() Problems
When using Val() if the input is not a number the function returns 0... however 0 IS a number..
so if I was to Val("0") it would return the same as Val("a").. so the statement
if Val(Variable)
DoSomething()
endif
wouldn't work if Variable was "0"
so if I was to Val("0") it would return the same as Val("a").. so the statement
if Val(Variable)
DoSomething()
endif
wouldn't work if Variable was "0"
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
IsNumeric()-discussion in the german forum with some code examples:
http://www.purebasic.fr/german/viewtopic.php?t=2203
the codes should be international....
PS:
btw, the Val() function is completely correct, because it is defined the way it works now.
http://www.purebasic.fr/german/viewtopic.php?t=2203
the codes should be international....
PS:
btw, the Val() function is completely correct, because it is defined the way it works now.
oh... and have a nice day.
- Michael Vogel
- Addict

- Posts: 2820
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: [PB 4.02] Val() Error
Val("a") returns 0 on other Basics, such as the C64 and Visual Basic, so there's
no need to alter its behaviour for PureBasic. It's been that way since the 1980s
so you'll just need to figure a way around it, like everyone else has been doing
for over 20 years.
Sounds like you need a different coding approach to it.
no need to alter its behaviour for PureBasic. It's been that way since the 1980s
so you'll just need to figure a way around it, like everyone else has been doing
for over 20 years.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
You would handle the validity of the zero result by checking the string used in Val(string) to see if all of it or at least the first character [Left(string,1)] is ="0" . I know you would have to consider a leading minus sign too. All other results would return the portion at the beginning of the string that was numeric, as it should.When using Val() if the input is not a number the function returns 0... however 0 IS a number..
Demivec

