Quote:
Originally posted by ganoderma@May 4 2007, 14:47
I am currently learning Visual Basic programming.
to learn, a friend taught me some things:
agreement window
Buttons to open other forms
and a simle 'dice' game.
though i wanted an highscore on the dice game and did this:
if form3.highscore.caption < form3.score.caption then
form3.highscore.caption = form3.score.caption
msgbox "new highscore!"
end if
however, this will result in 9 as the perfect score.
10, 11 and 12 are not higher according to the program (if you get it, it wont see that as highscore)
can anybody help me with this?
i can send the program itself or the source code if you need it.
|
The problem is that it's a string compare. It's like a dictionary...
The data type for the caption is a string, in a dictionary, you sort strings as such.
Ed
Edward
Edwardo <== misspelled, I know.
Anyhow, you would see that with this logic the sorting for numbers would be like:
1
11
15
19
2
21
25
3
35
etc...
So, you need to convert that string to a number and do a NUMERIC comparison, not a string comparison.
Convert a string to an integer with the Val() function.
if Val(form3.highscore.caption) < Val(form3.score.caption) then
form3.highscore.caption = form3.score.caption
msgbox "new highscore!"
end if
Good day.