PDA

View Full Version : VB Script, when executed getting error expected 'End'


venkat_m
08-11-2010, 01:05 AM
Hi all,

I am new to VB scripting and when i tried to execute below code, getting error as Expected 'End'. Please correct my code. thanks

Option Explicit

Function Amount( a,b)
Dim x,y
Tax =0.6
Amount = x+y*0.6
End Function

Dim Result
Result=Amount(2,4)

If Result <4 Then
msgbox("Amount is lessthan 4:")
Else if Result >4 Then
msgbox("Amount is Greaterthan 4:")
Else
msgbox("Amount is Equal to 4:")
End If

Old Pedant
08-11-2010, 02:40 AM
If Result <4 Then
msgbox("Amount is lessthan 4:")
Elseif Result >4 Then
msgbox("Amount is Greaterthan 4:")
Else
msgbox("Amount is Equal to 4:")
End If

ELSEIF is a single word. If you make it into two words, then you have to supply an END IF for the separated IF.

This, too, would thus work:

If Result <4 Then
msgbox("Amount is lessthan 4:")
Else
IF Result >4 Then
msgbox("Amount is Greaterthan 4:")
Else
msgbox("Amount is Equal to 4:")
End If
End If

But clearly the first form is simpler.