Solved

Calculate sum of currency textbox values

Posted on 2006-06-24
8
673 Views
Last Modified: 2008-01-09
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

Thanks in advance for your help.

Dave

0
Comment
Question by:dave_sky
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:iHadi
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

by:dave_sky
ID: 16976833
Hi,

Thanks for the response.
I used the code on a buttonClick event...
Tried the from load...
 
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

by:iHadi
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

by:dave_sky
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:pradeepsudharsan
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

by:
iHadi earned 500 total points
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

by:dave_sky
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

by:dave_sky
ID: 16979003
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now