Search code examples
vbscriptbackinputbox

How can I go back one step when processing a list of (user) choices?


I have a series of user choices (implemented as input boxes). Short Example:

Answer = InputBox("Choose: 1 - One 2 - Two", "Choose"))
If Answer = "1" Then 
    Answer = InputBox("Choose: 1 - Hi 2 - Hello", "Choose"))
        If Answer = "1" Then....

I want to know if VBScript can go back one step to the previous choice. From

InputBox("Choose: 1 - Hi 2 - Hello   3 - BACK", "Choose"))

If I input 3 I want to go one step back. I try history.go(-1), but there is an error. He want object "history".


Solution

  • Put the first selection in a Do loop, and break out of the loop with Exit Do only if something other than 3 is selected in the second prompt.

    Do
        Answer = InputBox("Choose: 1 - One 2 - Two", "Choose")
    
        If Answer = "1" Then 
            MyVal = LevelTwoSelect
        End If
    
        If MyVal <> 3 Then Exit Do
    
    Loop
    
    Function LevelTwoSelect
    
        Answer = InputBox("Choose: 1 - Hi 2 - Hello  3 - BACK", "Choose")
            If Answer = "1" Then LevelTwoSelect = 1
            If Answer = "2" Then LevelTwoSelect = 2
            If Answer = "3" Then LevelTwoSelect = 3
    
    End Function