Quantcast

vb6 help needed!

Transcend

My Nuts Are Flat
Apr 18, 2002
18,040
3
Towing the party line.
I need to validate input users enter via an InputBox, and if it is out of range, have a msgbox pop up and tell them to enter the data in the proper range

So far i can get it to do all of that, EXCEPT after it pops up the error, it enters that data into the form and continues on.

As soon as I enter cancel= true under the error message code, VB gives me a compile error.

If you dont enter any data and choose cancel, it gives you a type mismatch error.

Any ideas?



quote:
--------------------------------------------------------------------------------
intCount = 0
intTotalRoomsOcc = 0
Do While intCount <= 7
strInput = InputBox("Enter number of rooms occupied for floor " & _
FormatNumber((intCount) + 1, 0), "Occupency Needed")

If strInput = "" Or strInput > 30 Then
MsgBox "Please enter a Value between 0 and 30", vbOKOnly, "Input Error"
Cancel = True
End If

intRoomData = Val(strInput)
lblRoomsOcc(intCount).Caption = intRoomData
dblOccRate = intRoomData / 30
lblOccRate(intCount).Caption = FormatPercent(dblOccRate)
intTotalRoomsOcc = intTotalRoomsOcc + intRoomData
lblTotalRoomsOcc.Caption = intTotalRoomsOcc
dblOccSubTotal = intTotalRoomsOcc / 240
lblTotalOccRate.Caption = FormatPercent(dblOccSubTotal)
intCount = intCount + 1

Loop
End Sub

--------------------------------------------------------------------------------
 
You're processing the invalid data.

intCount = 0
intTotalRoomsOcc = 0
Do While intCount <= 7
strInput = InputBox("Enter number of rooms occupied for floor " & _
FormatNumber((intCount) + 1, 0), "Occupency Needed")

If strInput = "" Or strInput > 30 Then
MsgBox "Please enter a Value between 0 and 30", vbOKOnly, "Input Error"
Cancel = True
Else
intRoomData = Val(strInput)
lblRoomsOcc(intCount).Caption = intRoomData
dblOccRate = intRoomData / 30
lblOccRate(intCount).Caption = FormatPercent(dblOccRate)
intTotalRoomsOcc = intTotalRoomsOcc + intRoomData
lblTotalRoomsOcc.Caption = intTotalRoomsOcc
dblOccSubTotal = intTotalRoomsOcc / 240
lblTotalOccRate.Caption = FormatPercent(dblOccSubTotal)
intCount = intCount + 1
End If

Loop
End Sub
 

Transcend

My Nuts Are Flat
Apr 18, 2002
18,040
3
Towing the party line.
Originally posted by johnbryanpeters
You're processing the invalid data.

intCount = 0
intTotalRoomsOcc = 0
Do While intCount <= 7
strInput = InputBox("Enter number of rooms occupied for floor " & _
FormatNumber((intCount) + 1, 0), "Occupency Needed")

If strInput = "" Or strInput > 30 Then
MsgBox "Please enter a Value between 0 and 30", vbOKOnly, "Input Error"
Cancel = True
Else
intRoomData = Val(strInput)
lblRoomsOcc(intCount).Caption = intRoomData
dblOccRate = intRoomData / 30
lblOccRate(intCount).Caption = FormatPercent(dblOccRate)
intTotalRoomsOcc = intTotalRoomsOcc + intRoomData
lblTotalRoomsOcc.Caption = intTotalRoomsOcc
dblOccSubTotal = intTotalRoomsOcc / 240
lblTotalOccRate.Caption = FormatPercent(dblOccSubTotal)
intCount = intCount + 1
End If

Loop
End Sub
Doh! I fixed it since i posted this, but inever even noticed that. Thanks for pointing it out. I ended up changing it around, and using the Val function and isnumeric to make sure it was processing the proper data.
thanks man!
f