beginner visual basic coder- icnldued all the code if needed, but decTotalCharges = ComputeCharges(intDays, decMCharges, decSCharges, decLabFees, decRehabFees) is giving me a hard time - An error shows that says "Argument not specified for parameter 'decRehabFees' of "Public Function Compute Changes....."
Any idea how to fix this? Or any tips to simplify this code? It's for a college project lol.
Option Strict
Public Class Form1
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
'Declare variables
Dim intDays As Integer
Dim decMCharges As Decimal
Dim decSCharges As Decimal
Dim decLabFees As Decimal
Dim decRehabFees As Decimal
Dim decTotalCharges As Decimal
Dim decTax As Decimal
Dim decTotal As Decimal
Try
GetInfo(intDays, decMCharges, decSCharges, decLabFees, decRehabFees)
decTotalCharges = ComputeCharges(intDays, decMCharges, decSCharges, decLabFees, decRehabFees)
decTax = ComputeTax(decTotalCharges, decTax)
decTotal = ComputeTotal(decTotalCharges, decTax, decTotal)
Display(decTotalCharges, decTax, decTotal)
Catch ex As Exception
End Try
End Sub
Sub GetInfo(ByRef intDays As Integer, ByRef decMCharges As Decimal, ByRef decSCharges As Decimal, ByRef decLabFees As Decimal, ByRef decRehabFees As Decimal)
'Recieves values
intDays = CInt(txtDays.Text)
decMCharges = CDec(txtMCharges.Text)
decSCharges = CDec(txtSCharges.Text)
decLabFees = CDec(txtLabFees.Text)
decRehabFees = CDec(txtRehabFees.Text)
End Sub
Function ComputeCharges(ByRef decTotalCharges As Decimal, ByVal intDays As Integer, ByVal decMCharges As Decimal, ByVal decSCharges As Decimal, ByVal decLabFees As Decimal, ByVal decRehabFees As Decimal) As Decimal
'GetInfo(intDays, decMCharges, decSCharges, decLabFees, decRehabFees)
decTotalCharges = CDec(intDays * 300) + decMCharges + decSCharges + decLabFees + decRehabFees
End Function
Function ComputeTax(ByVal decTotalCharges As Decimal, ByRef decTax As Decimal) As Decimal
decTax = CDec(decTotalCharges * 0.07)
End Function
Function ComputeTotal(ByVal decTotalCharges As Decimal, ByVal decTax As Decimal, ByRef decTotal As Decimal) As Decimal
decTotal = decTotalCharges + decTax
End Function
Function Display(ByVal decTotalCharges As Decimal, ByVal decTax As Decimal, ByVal decTotal As Decimal) As String
lblTax.Text = decTax.ToString("c")
lblTotal.Text = decTotal.ToString("c")
lblTotalCharges.Text = decTotalCharges.ToString("c")
End Function
End Class
ComputeTaxis declared as aFunctionbut it doesn't return anything, although you are using a single output parameter. That function should be declaredFunction ComputeTax(decTotalCharges As Decimal) As Decimaland then implementReturn decTotalCharges * 0.07Dand then calleddecTax = ComputeTax(decTotalCharges). Several other methods should be changed similarly.Suband a single output means aFunction, both with noByRefparameters. If there are multiple outputs then you'll need at least oneByRefparameter. If there is one "primary" output then use aFunctionand return that, usingByRefparameters for the rest, e.g.Integer.TryParse. If there is no single "primary" output, use aSuband allByRefparameters.