Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm a beginner and don't understand why my code is throwing "Expression Expected"

Tags:

vb.net

I am new to development and am receiving the error "Expression Expected" when I attempt to compile the code below. What am I doing wrong?

Public Class Form1

    Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

        Dim Occupation As String = CStr(txtOccupation.Text)
        Dim Bill As Double = CDbl(txtBill.Text)
        Dim Tip As Double = CDbl(txtTip.Text)

        lstOutput.Text = Bill * (1 + if (Tip<1,Tip,Tip/100))

    End Sub
End Class
like image 261
Davey Avatar asked Mar 13 '09 21:03

Davey


1 Answers

I'm guessing the exception is being thrown on on the last line

lstOutput.Text = Bill * (1 + if (Tip<1,Tip,Tip/100))

You used "if" which is used in an if...then statement, but i bet you meant iif, which is a function

lstOutput.Text = Bill * (1 + IIf (Tip<1,Tip,Tip/100))

just add that one extra "i" and you should be fine

Article explaining the difference between "IF" and "IIF()"

like image 167
Michael La Voie Avatar answered Nov 24 '22 01:11

Michael La Voie