Vb.net 在tip计算器中使用函数
我必须在作业中使用函数,但我不确定它应该是什么样子。这就是我现在拥有的。。。帮助写一行vb中声明的函数表示错误Vb.net 在tip计算器中使用函数,vb.net,Vb.net,我必须在作业中使用函数,但我不确定它应该是什么样子。这就是我现在拥有的。。。帮助写一行vb中声明的函数表示错误 Dim BillTotal, TipAmount, PerPerson, TipDecimal, Total As Double Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Butt
Dim BillTotal, TipAmount, PerPerson, TipDecimal, Total As Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Tip Amount: " & TipAmount & Chr(13) & "Per Person: " & PerPerson & Chr(13) & "Total: " & Total & Chr(13))
End Sub
Function Total(ByVal BillTotal As Double) As Double
BillTotal = mtbBill.Text
TipAmount = (mtbTip.Text / 100) * BillTotal
TipDecimal = (mtbTip.Text / 100)
PerPerson = ((BillTotal * (1 + TipDecimal)) / mtbSharedBy.Text)
Total = BillTotal * (1 + TipDecimal)
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(String.Format("Tip Amount: {0}{1} per person{2}{1} Total:{3}{1}", TipAmount, vbNewLine, PerPerson,Total()))
' Here I replaced the code with String.Format making it easier to read.
' You specify {0}, {1}, {2}, {n} where the number is the order of the parameter.
' Then at the end of your string you specify the parameter name such as TipAmount, vbNewLine(which is essentially Chr(13), PerPerson, and Total
End Sub
Function Total() As Double ' Removed the parameter passed into the function as it's not required.
BillTotal = mtbBill.Text
TipAmount = (mtbTip.Text / 100) * BillTotal
TipDecimal = (mtbTip.Text / 100)
PerPerson = ((BillTotal * (1 + TipDecimal)) / mtbSharedBy.Text)
Return( BillTotal * (1 + TipDecimal))
End Function
你有问题吗?它有用吗?启用选项Strict。始终“帮助编写vb中声明的函数表示错误的行”。那是一串毫无意义的词。如果您的IDE告诉您有错误,并且您希望得到帮助,请确切地告诉我们错误发生的位置以及错误消息的确切内容。您需要同时启用Option Strict和Option Strict吗?出于什么原因?关闭Option Strict是不好的做法。关闭它可以隐藏所有类型的错误。