Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Calculate sum of currency textbox values

Posted on 2006-06-24
Medium Priority
811 Views
Hi Experts,

I need help on what is probably a very basic question for someone that knows what they are doing.

Windows Application, VB.net 2005, SQL Server 2005.

TextBoxA = Currency value
TextBoxB = Currency value
TextBoxC = Currency Value
TextBoxD = Currency Value
(Values can be Null)

TextBoxE = Sum of the values above

Dave

0
Question by:dave_sky
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 3

LVL 13

Expert Comment

ID: 16976732
Hi

The following code does exactly what you explained (according to how I understood it):

Dim a(4) As Decimal
Dim Result As Decimal
a(0) = System.Convert.ToDecimal(Val(TextBoxA.Text))
a(1) = System.Convert.ToDecimal(Val(TextBoxB.Text))
a(2) = System.Convert.ToDecimal(Val(TextBoxC.Text))
a(3) = System.Convert.ToDecimal(Val(TextBoxD.Text))

Result = a(0) + a(1) + a(2) + a(3)
TextBoxE.Text = Result.ToString
0

Author Comment

ID: 16976833
Hi,

Thanks for the response.
I used the code on a buttonClick event...

I can't get the code to work, maybe I wasn't clear on my post.

Using the ButtonClick event, TextBoxes A,B,C,&D show their individual values in TextBoxE but the sum of the TextBoxes are not calculated.

0

LVL 13

Expert Comment

ID: 16976934
Can you describe whats the output of the button event more, like give me an example of whats happening and the correct values you want
0

Author Comment

ID: 16977347
HI,

Let's try this:

All TextBox Null values are \$0.00
Properties are set to Currency.

I enter these amounts:
TextBoxA = \$10.00
TextBoxB = \$10.00
TextBoxC = \$10.00
TextBoxD = \$0.00

After buttonClick event:
TextBoxE changes from \$0.00 to 0 (Should be = \$30.00)

I hope this helps.

0

LVL 7

Expert Comment

ID: 16977415
TextBoxE.Text = (decimal.Parse(TextBoxA.Text)+decimal.Parse(TextBoxB.Text)+decimal.Parse(TextBoxC.Text)+decimal.Parse(TextBoxD.Text)).ToString

0

LVL 13

Accepted Solution

ID: 16977860
Dim a(4) As Decimal
Dim Result As Decimal
a(0) = System.Convert.ToDecimal(Val(TextBoxA.Text.Replace("\$", "")))
a(1) = System.Convert.ToDecimal(Val(TextBoxB.Text.Replace("\$", "")))
a(2) = System.Convert.ToDecimal(Val(TextBoxC.Text.Replace("\$", "")))
a(3) = System.Convert.ToDecimal(Val(TextBoxD.Text.Replace("\$", "")))

Result = a(0) + a(1) + a(2) + a(3)
TextBoxE.Text = Format(Result, "\$0.00")
0

Author Comment

ID: 16978407

iHadi, the code worked great! thank you very much.

pradeepsudharsan, i'm sorry but I got an error message with your code:
"The input string was not in the correct format."

0

Author Comment

ID: 16979003
0

## Featured Post

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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
Course of the Month9 days, 21 hours left to enroll