It’s because you're redeclaring loginSuccess
inside the If
, so VBScript treats it like a new local variable there, exactly like what @Shrotter said
You could try moving the Dim loginSuccess outside the If block
It should look something like this:
Dim username
Dim loginSuccess
username = InputBox("Enter your name:")
If username = "admin" Then
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