I have a simple program
Set Textbox5= myPage1.Controls("Textbox5")
Set Textbox7= myPage1.Controls("Textbox7")
if Textbox5.value > Textbox7.value then
msgbox("cheater cheater cheater")
elseif Textbox5.value <= Textbox7.value then
msgbox("good job")
end if
The problem is that when I input "10" for textbox7, it reads it as "1", and alternatively if I input "21", it reads it as "2" . It only looks at the first digit!
What is going on here??? am I missing something?
Yep! :)
You are comparing strings, not numbers. This is a common problem that probably every VB programmer runs into sooner or later (probably in other languages, too).
A string is simply a bunch of characters, read (depending on what part of the owrld you come from) from left to right. In these terms, "
21" is higher than, say, "
100". VB is not simply looking at the first character. It is looking at as many as necessary to determine the sequence. For example, you'd find that "11122233
35" is higher than "11122233
25"
If you use the
Val() function to convert them to numeric values your code should work.