I'm working on a basic login check in VBS on Windows, just running from a .vbs file. I’ve been trying to set a loginSuccess flag based on a username check. It prints the welcome message correctly when the name matches, but the variable loginSuccess always ends up False outside the If. I can’t tell if it’s a scoping thing or what.
Dim username
username = InputBox("Enter your name:")
If username = "admin" Then
Dim loginSuccess
loginSuccess = True
MsgBox "Welcome, admin!"
Else
loginSuccess = False
MsgBox "Access Denied"
End If
If loginSuccess Then
MsgBox "You're logged in"
Else
MsgBox "Login failed"
End If
No error shows up but the last message always says "Login failed" even when I type "admin". That first MsgBox in the If block works fine so I know the condition hits.
loginSuccessoutside the if clause.