Link to home
Start Free TrialLog in
Avatar of JMaher
JMaher

asked on

random inaccuraciy in my project

I am working on a program that puts (say) eggs into cartons. Each carton holds 30 eggs. The user can put an egg into any carton and position they want, provided it is not already used. So I have the following code in the Form Load part of the program:
MaxCart = GetSetting("GolfBalls", "Carts", "number", 400)
 MaxCart is also a Public variable.
Now when I try to enter a number in the "Carton" section, I am told that the number is too high! Here is that code:

Private Sub cmdAdd_Click()

If txtCart.Text > MaxCart Then
msgtxt = "There are only " & MaxCart & " cartons!"
msghead = "Number too high"
MsgBox msgtxt, , msghead
txtCart.SetFocus
Exit Sub
End If

There is other stuff as well, but this is the offending bit. If I enter number 4, all is OK. But if I enter 5, I get the message box up. Also other numbers, like 6, 7, 8, 65, 98 etc. But number 399 is OK! So are other random numbers! I have stepped through the program, and this is where I believe the problem can only be. I even set up a text box to display MaxCart and it always says 400. Any ideas?
Avatar of JMaher
JMaher

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JMaher

ASKER

As usual, an easy answer... but could you tell me WHY testing for string the way I have been will allow some numbers but not others?
All I can tell you is VB doesn't compare strings and numeric values...

Cheers!