473,382 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

vb is only looking at first digit in number

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
3 1783
Killer42
8,435 Expert 8TB
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
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
Killer42
8,435 Expert 8TB
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

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

Similar topics

7
by: mydejamail | last post by:
I am looking for a script that generates PIN Numbers. Is there one available somewhere out there? I don't mind algorithms if they will be easy to implement in PHP. Regards
1
by: J Jungeblut | last post by:
Hi! I have an Access 97 Database which I have to read from with C++. All the text-fields are returned to c++ completely, but when a field contains a number greater than 9 the return value to c++...
2
by: hikmaz | last post by:
I am trying to get the rightmost digits (%10) of a number (taken from the user) and store it into successive array locations and get rid of the rightmost digit (\10) to store the next and so on and...
3
by: gigs68 | last post by:
What script would I need to write (vb.net) to validate a credit card number's length and first digit input to a text box (i.e., Visa Length=16 digits, first digit starts with a 4)? Thanks Bryan
2
by: savannahjr | last post by:
Very much a newbi here. I'm using Access 2003/WInXP. Most of the tips I use came from this forum but I can't find the answer to this question. I have a form (frmCircuits) that has 3 main fields...
7
by: southernsunsations | last post by:
/******************************************************************\ * * * * Date: 09.06.2007 ...
4
by: Mastastealth | last post by:
I'm trying to create a program to read a certain binary format. I have the format's spec which goes something like: First 6 bytes: String Next 4 bytes: 3 digit number and a blank byte --- Next...
2
by: penguinbob31 | last post by:
I'm writing a program that is supposed to take the first digit of every number in a list of numbers and count how many times each first digit appears. I can't seem to get the program to work...
2
by: nofear | last post by:
I have 2 tables with 1 field each the filed of the fist table has a 3 digit number stored as text and the field of the second table has a 6 digit number stored as text I'd like to select each 6...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.