I was trying to make a calculator in VBScript to test my skill, but came across an error. My program uses multiple else if statement to test what the user has input.
Here is my code below:
Dim head
Dim msg1, msgErr, msgAns
Dim input1, num1, num2
Dim ans
head = "Calculator"
msg1 = msgBox("Ruan's Vbscript calculator",0,head)
input1 = inputBox("How do you want to calculate? You can type (+ - * /)",head)
num1 = inputBox("Enter your first number",head)
num2 = inputBox("Enter your second number",head)
if (input1 = vbcancel) then
wscript.quit()
else if (input1 = "+") then
ans = num1 + num2
else if (input1 = "-") then
ans = num1 - num2
else if (input1 = "*") then
ans = num1 * num2
else if (input1 = "/") then
ans = num1 / num2
else
msgErr = msgBox("Make sure you type '+' or '-' or '*' or '/' with no extra letter or spaces","Error")
end if
msgAns = msgBox "Your answere is: " + head
When I run the program, the error says: "Expected end of statement". I don't see the problem here, as I have end if after all those else if statements.
ElseIfw3schools.com/vbscript/vbscript_conditionals.aspinput1 = vbcanceldoes not work as some may think.