Link to home
Start Free TrialLog in
Avatar of HKH1967
HKH1967Flag for Saudi Arabia

asked on

VB.NET CALCULATION null

I HAVE THIS SQL IN VB.NET THAT CONTAIN SOME TIMES NULL VALUE
While running the vb.net it give error because of null value

        Dim TotalDeducttion As Decimal = (txtAgentCommission.Text) + CDec(txtAmendCharges.Text) + CDec(txtTelexCharges.Text) + CDec(txtCollectionCharges.Text) + CDec(txtSwiftCharges.Text) + CDec(txtAntOtherCharges.Text)

how to fix it in vb.net
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this code



Dim TotalDeducttion As Decimal = GetText(txtAgentCommission) + GetText(txtAmendCharges) + GetText(txtTelexCharges) + GetText(txtCollectionCharges) + GetText(txtSwiftCharges) + GetText(txtAntOtherCharges)



Private Function GetText(txt As Textbox) As Decimal
     If String.IsNullOrEmpty(txt.Text) Then 
        Return 0
     Else
        Return Decimal.Parse(txt.Text)
End Function

Open in new window

Add an

End If

after line 9.
Avatar of HKH1967

ASKER

Genius
I try it and i got the the following error
Conversion from string "" to type 'Decimal' is not valid.

the code
Dim DocAmount As Decimal = CDec(txtDocAmount.Text) - CDec(CDec(txtAgentCommission.Text) + CDec(txtAmendCharges.Text) + CDec(txtTelexCharges.Text) + CDec(txtCollectionCharges.Text) + CDec(txtSwiftCharges.Text) + CDec(txtAntOtherCharges.Text))

was in the green color


Avatar of HKH1967

ASKER

Genius

CodeCruiser:
Add an

End If

after line 9.

i have the end if and the result as above
Avatar of HKH1967

ASKER

Genius

sorry the error as follows:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30288: Local variable 'TotalDeducttion' is already declared in the current block.

Source Error:


Line 176:
Line 177:        Dim TotalDeducttion As Decimal = GetText(txtAgentCommission) + GetText(txtAmendCharges) + GetText(txtTelexCharges) + GetText(txtCollectionCharges) + GetText(txtSwiftCharges) + GetText(txtAntOtherCharges)
Line 178:        Dim TotalDeducttion As Decimal
Line 179:        lblTotalDeduction.Text = TotalDeducttion
Line 180:        lblNetproceeds.Text = DocAmount
 

Source File: E:\Projects\NcbWork\Default.aspx.vb    Line: 178
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HKH1967

ASKER

thanks alot
Glad to help :-)