user4119689
user4119689

Reputation:

VBS Calculator issues

In this calculator program, the + works but -, * and / do not work. Why?

Option Explicit
Dim IB, Sum1, Sum2, Sym
Sum1 = InputBox("Enter first #NO", "VBS Calculator")
If Not IsNumeric(IB) Then
    MsgBox "Please enter a valid Number"
ElseIf IsNumeric(IB) Then
    If Not IsNumeric(IB) Then
        MsgBox " Please enter a valid Number"
    ElseIf IsNumeric(IB) Then
        Sum2 = InputBox("Enter second #NO", "VBS Calculator")
        Sym = InputBox("Enter a law of Arithmetic", "VBS Calculator")
        If Sym = "+" Then MsgBox (CInt(Sum1) + CInt(Sum2))
    ElseIf Sym = "-" Then MsgBox (CInt(Sum1) - CInt(Sum2))
    ElseIf Sym = "/" Then MsgBox (CInt(Sum1) / CInt(Sum2))
    ElseIf Sym = "*" Then MsgBox (CInt(Sum1) * CInt(Sum2))
    End If
End If

Upvotes: 0

Views: 444

Answers (1)

Scott C
Scott C

Reputation: 1660

If you put the statement on the same line as the if then then any else clauses have no effect. e.g.

if a=b then statement

is the logical equivalent of

if a = b then
    statement
end if

Your code has other issues too, like checking for Elseif IsNumeric(IB) then followed by if Not IsNumeric(IB) then The second if will always be skipped, going straight to the elseif

Upvotes: 1

Related Questions