I have a select case construct that only allows two options but if I know users, someone will not enter either just 'P' or 'L' so I want the Case Else clause to loop back to the start and make then do it again. I could simply say goto but I know just enough about coding to know that sort of construct is frowned upon so what is the 'correct' way to return to represent the InputBox that preceds my Case Select?
Thanks,
Ken
make user do it again
-
- Panoramic Lounger
- Posts: 8225
- Joined: 25 Jan 2010, 09:09
- Location: retirement
-
- Administrator
- Posts: 78789
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: make user do it again
For example like this:
Code: Select all
Dim strPrompt As String
Dim strInput As String
strPrompt = "Please enter P or L"
Do
strInput = UCase(InputBox(strPrompt))
strPrompt = "Do me a favour! Please enter only P or L. Thank you!"
Loop Until strInput = "P" Or strInput = "L"
Select Case strInput
Case "P"
' action for P
Case "L"
' action for L
End Select
Best wishes,
Hans
Hans
-
- Panoramic Lounger
- Posts: 8225
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: make user do it again
Ah yes! Once I'd posted my problem the Lounge Magic began to have an effect and I had the idea of "do/while input is not right" but I couldn't figure out how to apply it. This does the job nicely.
![ThankYou :thankyou:](./images/smilies/thankyou.gif)
Ken
![ThankYou :thankyou:](./images/smilies/thankyou.gif)
Ken