我是开发新手,在尝试编译下面的代码时收到错误“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
答案 0 :(得分:9)
我猜测最后一行正在抛出异常
lstOutput.Text = Bill * (1 + if (Tip<1,Tip,Tip/100))
你在if ... then语句中使用了“if”,但我打赌你的意思是iif,这是一个函数
lstOutput.Text = Bill * (1 + IIf (Tip<1,Tip,Tip/100))
只需添加一个额外的“我”就可以了。
答案 1 :(得分:0)
如果您使用的是2008年?或者以后if是好的
Dim tipT As New TextBox
Dim Bill As Decimal = 9D
Dim tip As Decimal = 20
tipT.Text = Convert.ToString(Bill * If(tip >= 1, tip / 100, tip))