我是开发新手,在尝试编译以下代码时收到错误消息“Expression Expected”。我究竟做错了什么?
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
最佳答案
我猜这是最后一行抛出的异常
lstOutput.Text = Bill * (1 + if (Tip<1,Tip,Tip/100))
您使用了if ... then语句中使用的“if”,但是我敢打赌您的意思是iif,这是一个函数
lstOutput.Text = Bill * (1 + IIf (Tip<1,Tip,Tip/100))
只需添加一个额外的“i”,就可以了
Article explaining the difference between "IF" and "IIF()"
关于vb.net - 我是一个初学者,不明白为什么我的代码会抛出 "Expression Expected",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/644668/