|
-
Jul 15th, 2007, 09:04 AM
#1
Thread Starter
New Member
Question About Error I am receiving When Calling A Function
Hello, I am writing an application to gain an understanding of how to use Functions and Sub procedures. I am receiving the following error when I am trying to call my functions. If anybody can offer any feedback it would be appreciated. Please view my code below.
Here is the error I am receiving:
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "" to type 'Decimal' is not valid.
The program '[2456] Function_Problem2.exe' has exited with code 0 (0x0).
Here is the code to Call The Functions
'Declaring Variables'
Dim decSubtotal As Decimal ' Holds Services & Labor'
Dim decPart As Decimal ' Holds parts from other services'
Dim decTax As Decimal ' Holds tax on parts'
Dim decTotalFees As Decimal ' Holds the total of everything'
'The breakpoint at RunTime is going to this First line of code'
decSubtotal = OilLubeCharges(txtSerLabor.Text) + FlushCharges(txtSerLabor.Text) + MiscCharges(txtSerLabor.Text) + OtherCharges(txtSerLabor.Text)
decPart = OtherCharges(txtPart.Text)
decTax = TaxCharges(txtTax.Text)
decTotalFees = TotalCharges(txtTotalFees.Text)
Here are the Functions I wrote in my form
Function OilLubeCharges(ByRef pdecOil As Decimal) As Decimal
Dim decoilChangeCost As Decimal
If chkOilChange.Checked = True Then
decoilChangeCost = " $26.00 "
Else
decoilChangeCost = " $18.00 "
End If
Return decoilChangeCost
End Function
Function FlushCharges(ByRef pdecFlushes As Decimal) As Decimal
Dim decFlushes As Decimal
If chkRadFlush.Checked = True Then
decFlushes = " $30.00 "
Else
decFlushes = " $80.00 "
End If
Return decFlushes
End Function
Function MiscCharges(ByRef pdecMisc As Decimal) As Decimal
Dim decMisc As Decimal
If chkInspection.Checked = True Then
decMisc = " $15.00 "
ElseIf chkMuffler.Checked = True Then
decMisc = " $100.00 "
Else
decMisc = " $20.00 "
End If
Return decMisc
End Function
Function OtherCharges(ByRef pdecOther As Decimal) As Decimal
Dim decPart As Decimal
Dim decLabor As Decimal
Dim decTotal As Decimal
decPart = Val(txtPart.Text)
decLabor = Val(txtLabor.Text)
txtPart.Text = decPart
txtLabor.Text = decLabor
decTotal = decPart + decLabor
Return decTotal
End Function
Function TaxCharges(ByVal amount As Decimal) As Decimal
Dim decSalesTax As Decimal
decSalesTax = amount * 6%
Return decSalesTax
End Function
Function TotalCharges(ByVal total As Decimal) As Decimal
Dim decTotal As Decimal
decTotal = txtSerLabor.Text + txtParts.Text + txtTax.Text + txtTotalFees.Text
Return decTotal
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|