By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

vb is only looking at first digit in number

P: 2
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?
thanks all
May 7 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 5K+
P: 8,434
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 "1112223335" is higher than "1112223325"

If you use the Val() function to convert them to numeric values your code should work.
May 8 '07 #2

P: 2
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 "1112223335" is higher than "1112223325"

If you use the Val() function to convert them to numeric values your code should work.



I am using VBScript which is part of Outlook 2003. when I type in Val(), it is a type mismatch. I don't think VBScript recognizes val(), any ideas? I'm currently using textbox1.value (same thing?)
May 9 '07 #3

Expert 5K+
P: 8,434
I am using VBScript which is part of Outlook 2003. when I type in Val(), it is a type mismatch. I don't think VBScript recognizes val(), any ideas? I'm currently using textbox1.value (same thing?)
Try looking up data conversion functions in the VBScript (or is it VBA?) doco.
May 9 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.