I can't figure out how to make this work:
If
CInt(txtLengthStay.Text) Or CInt(txtMedication.Text) Or CInt(txtSurgical.Text) Or CInt(txtLabFees.Text) Or CInt(txtPhysical.Text) <= "-1" ThenMessageBox.Show(
"Please do not enter numbers less than 0", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)The point is if the user enters a number less than 0, a message box will pop up to let them know that only numbers 0 and up are allowed. However, everytime I run the program any number above 30, the messagebox pops up. What am I doing wrong? Thanks for the help guys!

AlanRank #669 · 3.6K reputationPosted Oct 16, 2007, 1:04 AM EDT
Try it this way (I've changed the ORs to +'s and "-1" to -1):
If CInt(txtLengthStay.Text) + CInt(txtMedication.Text) + CInt(txtSurgical.Text) + CInt(txtLabFees.Text) + CInt(txtPhysical.Text) <= -1 Then
Sonny Thai11 reputationPosted Oct 16, 2007, 7:39 AM EDT
AlanRank #669 · 3.6K reputationPosted Oct 16, 2007, 8:53 AM EDT
The point is that if you add any arbitary set of integers together, the total can only be less than zero if at least one of those numbers is itself less than zero.
However, you can do it more explicitly with:
If CInt(txtLengthStay.Text) < 0 Or CInt(txtMedication.Text) < 0 Or CInt(txtSurgical.Text) < 0 Or CInt(txtLabFees.Text) < 0 Or CInt(txtPhysical.Text) < 0 Then
Sonny Thai11 reputationPosted Oct 16, 2007, 9:34 AM EDT