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!
Sonny ThaiPosted Oct 16, 2007, 1:34 PM
AlanPosted Oct 16, 2007, 12:53 PM
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 ThaiPosted Oct 16, 2007, 11:39 AM
AlanPosted Oct 16, 2007, 5:04 AM
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