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?
JMaherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JMaherAuthor Commented:
Edited text of question.
0
mcriderCommented:
You need to test for value, not string...

If Val(txtCart.Text) > MaxCart Then


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JMaherAuthor Commented:
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?
0
mcriderCommented:
All I can tell you is VB doesn't compare strings and numeric values...

Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.