I have a non-VBA program that takes user input from a series of InputBoxes activated by a loop. I need it so that, if the user clicks the "cancel"button, it breaks out of the loop. Unfortunately, the "cancel" button doesn't do this, and instead returns an empty string, which then gets passed to my input validation function, fails, and gives a failed validation message. Clicking "ok" on the validation message just pops up the InputBox again. This creates an infinite loop of cancel > ok > cancel > ok. I need it to work so that, when the user clicks "cancel", the InputBox closes without sending any input. Is this possible? Thanks for any help :)
Here is my code:
'Assign value to variable
strAmountInput = InputBox("Please enter the monthly rainfall for " & strMonth)
If Validation(strAmountInput) = True Then
'Set Value for dblAmount
dblAmount = CDbl(strAmountInput)
'Add monthly rainfall amount to array, using i as index
dblMonthlyRain(i) = dblAmount
'Add item displaying monthly rainfall to listbox
lstMonthlyRainfall.Items.Add("Rainfall for " & strMonth & " = " & CStr(dblMonthlyRain(i)))
Else
'Prevent loop from advancing if validation fails, forces user to enter valid input before moving on
i -= 1
End If
_______________________________________________________________________________________
Private Function Validation(Amount As String) As Boolean
'Validate user input for InputBox
If IsNumeric(Amount) = False Then
MessageBox.Show("Please enter numbers only")
Return False
Else
Return True
End If
End Function