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
おかげで、 エリック
ようこそEric。 vbaタグの説明でわかるように、VBAとVB.NETは同等ではありません。 –
ありがとう、私はそれを訂正した –
コードにブレークポイントを置く(左の余白をクリックし、赤い点を得る)ステップスルー。変数にマウスポインタを合わせると、現在の値を取得できます。 – peterG