Created August 2016

In VBScript, It's always "Elseif" and never "Else If"

Simple "Else" is no problem.

If 1 = 1 Then
	Wscript.Echo("1 is 1")
Else
	Wscript.Echo("1 is not 1")
End If
Result:
C:\cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

1 is 1

"Elseif" is correct.

' correct syntax "Elseif"
If 1 = 1 Then
	Wscript.Echo "1 is 1"
Elseif 2 = 2 Then
	Wscript.Echo "1 is 2"
Elseif 3 = 3 Then
	Wscript.Echo "1 is 3"
End If
Result:
C:\cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

1 is 1

"Else if" with a space is WRONG.

' The Wrong Syntax - no "Else If" in VBScript
If 1 = 1 Then
	Wscript.Echo "1 is 1"
Else If 2 = 2 Then
	Wscript.Echo "1 is 2"
Else If 3 = 3 Then
	Wscript.Echo "1 is 3"
End If
Result:
C:\cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\test.vbs(7, 7) Microsoft VBScript compilation error: Expected 'End'
blog comments powered by Disqus