VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Why doesn't this For loop work? (https://forums.vandyke.com/showthread.php?t=13023)

djvj 02-15-2018 12:31 PM

Why doesn't this For loop work?
 
Trying to automate a simple login process before I expand it to work on multiple devices that have different prompts, but I keep getting an Unexpected 'Next' error when it's ran and not sure why:

Code:

        For x = 0 To 2        ' Loop this code 2 times (once for username, and again for password)
                result = crt.screen.waitforstrings ("ACS5.5 username:", "ACS5.5 password:", "password:", 5)        ' wait 5 seconds for each try
                Select Case result
                        Case 0
                                msgbox "timeout occurred"
                        Case 1
                                crt.Screen.Send usr & VbCr        ' Send your username followed by a carriage return
                        Case 2
                                crt.Screen.Send pw & VbCr        ' Send your password followed by a carriage return
                        Case 3
                                crt.Screen.Send pw & VbCr        ' Send your password followed by a carriage return
                Crt.Sleep 1000        ' wait 1 second
        Next

The error might be obvious but not used to coding in VBS.

ekoranyi 02-15-2018 01:24 PM

Hi djvj,

It looks like the For loop error may be a bit of a red herring.

I think it just a matter of your Select Case missing the End Select.

Code:

Select Case result
    Case 0
        msgbox "timeout occurred"
    Case 1
        crt.Screen.Send usr & VbCr
    Case 2
        crt.Screen.Send pw & VbCr
    Case 3
        crt.Screen.Send pw & VbCr
End Select

Does making this change get you the behavior you're looking for?

djvj 02-15-2018 02:39 PM

Thank you! Yes that worked.


All times are GMT -6. The time now is 03:16 PM.