Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB.NET CALCULATION null

Posted on 2011-10-21
8
Medium Priority
?
424 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:HKH1967
  • 4
  • 4
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37005801
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

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37005805
Add an

End If

after line 9.
0
 

Author Comment

by:HKH1967
ID: 37005873
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


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:HKH1967
ID: 37005877
Genius

CodeCruiser:
Add an

End If

after line 9.

i have the end if and the result as above
0
 

Author Comment

by:HKH1967
ID: 37006127
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
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 37008101
>Local variable 'TotalDeducttion' is already declared in the current block.

Is that not self explanatory? Remove

Dim TotalDeducttion As Decimal
0
 

Author Closing Comment

by:HKH1967
ID: 37014533
thanks alot
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37014554
Glad to help :-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question