我是編程新手,剛剛將我的專業從EE轉換到IT - 在使用Visual Basic函數時遇到問題。我認爲我的錯誤是在函數聲明的某個地方,但我不完全確定。該程序應該使醫院所花的時間乘以我聲明的常數= 350,並將所有雜項費用加到該數字中,但是我返回0.任何人都可以幫助我發現錯誤嗎?Visual Basic函數的變量聲明中的錯誤
Visual Basic代碼:
Const decStay_Rate As Decimal = 350
Private decLength As Integer
Private decMedication As Decimal
Private decSurgical As Decimal
Private decLab As Decimal
Private decPhysical As Decimal
Private decTotalStayPrice As Decimal
Private decTotalMiscCharges As Decimal
Private decTotal As Decimal
Dim decStay As Decimal
Function validateInputField() As Boolean
If Not Decimal.TryParse(txtLength.Text, decLength) Then
MessageBox.Show("Stay Length must be numeric")
End If
If Not Decimal.TryParse(txtMedication.Text, decMedication) Then
MessageBox.Show("Medication cost must be numeric")
End If
If Not Decimal.TryParse(txtSurgical.Text, decSurgical) Then
MessageBox.Show("Surgical cost must be numeric")
End If
If Not Decimal.TryParse(txtLabFees.Text, decLab) Then
MessageBox.Show("Lab fees must be numeric")
End If
If Not Decimal.TryParse(txtPhysicalRehab.Text, decPhysical) Then
MessageBox.Show("Physical Rehab cost must be numeric")
End If
Return True
End Function
Function CalcStayCharges(ByVal decLength As Decimal) As Decimal
Dim decTotalStayPrice As Decimal
decTotalStayPrice = decLength * decStay_Rate
Return decTotalStayPrice
End Function
Function CalcMiscCharges(ByVal decmedication As Decimal, ByVal decsurgical As Decimal, ByVal decLab As Decimal, ByVal decPhysical As Decimal) As Decimal
Dim decTotalMiscCharges As Decimal
decTotalMiscCharges = decmedication + decsurgical + decLab + decPhysical
Return decTotalMiscCharges
End Function
Private Function CalcTotalCharges(ByVal decTotalStayPrice As Decimal, ByVal decTotalMiscCharges As Decimal) As Decimal
Dim decTotalCharge As Decimal
decTotalCharge = decTotalStayPrice + decTotalMiscCharges
Return decTotalCharge
End Function
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
txtLabFees.Text = String.Empty
txtLength.Text = String.Empty
txtMedication.Text = String.Empty
txtPhysicalRehab.Text = String.Empty
txtSurgical.Text = String.Empty
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim decTotal As Decimal
lblOutput.Text = String.Empty
If validateInputField() Then
decTotal = CalcTotalCharges(decTotalStayPrice, decTotalMiscCharges)
lblOutput.Text = decTotal.ToString("c")
End If
End Sub
感謝, 埃裏克
歡迎埃裏克。正如你在vba標籤描述中看到的那樣,VBA和VB.NET不是等價的。 –
謝謝,我糾正了這個問題 –
在代碼中放置一個斷點(點擊左邊的空白處,得到一個紅色的點)然後繼續。您可以將鼠標指針懸停在變量上以獲取其當前值。 – peterG