buddy2000
02-05-2011, 05:38 PM
I am new to Vb and need help. I need a user to input 1 or 2 only. I need the loop to validate this an not crash. Here is what I have and it does not work.
Dim LocationCode As Integer
Dim SalesAmount As Single
Dim Bonus As Single
Dim Commision As Single
Dim IsValid As Boolean
Dim i As Integer
' set isValid = to false
IsValid = False
Do Until IsValid = True
'Ask the user to input Location code into inout box
LocationCode = InputBox("Enter a Location Code 1 or 2", "Location Code", 1)
' Cofirms that the user entered a 1 or 2
If LocationCode <> 1 Or 2 Then IsValid = False
'If not a 1 or 2 the user sees an error message
MsgBox "Sorry you did not enter a 1 or 2. Please try again."
End
For i = 1 To 9
If LocationCode = 1 Or 2 Then
IsValid = True
Exit For
End If
Next
Loop
SalesAmount = InputBox("enter amount")
End Sub
Dim LocationCode As Integer
Dim SalesAmount As Single
Dim Bonus As Single
Dim Commision As Single
Dim IsValid As Boolean
Dim i As Integer
' set isValid = to false
IsValid = False
Do Until IsValid = True
'Ask the user to input Location code into inout box
LocationCode = InputBox("Enter a Location Code 1 or 2", "Location Code", 1)
' Cofirms that the user entered a 1 or 2
If LocationCode <> 1 Or 2 Then IsValid = False
'If not a 1 or 2 the user sees an error message
MsgBox "Sorry you did not enter a 1 or 2. Please try again."
End
For i = 1 To 9
If LocationCode = 1 Or 2 Then
IsValid = True
Exit For
End If
Next
Loop
SalesAmount = InputBox("enter amount")
End Sub