Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add?

Status
Not open for further replies.

ErroR

Technical User
Apr 9, 2001
79
US
Very new to VB.. building this little piece of code just to learn mainly..

Very simple program, I have 3 text boxes which each accept numeric values. I have a calculate button that I want it to sum up the values in the 3 text boxes..

For example

txtCash
txtCheck
txtMisc
txtTotal
cmdCalculate

I thought that the following would work one the On_click for the Calculate command button:

txtTotal = txtCash + txtCheck + txtMisc

But I guess it is not quite that simple..

I'm not even sure I'm going about this right at all, any help; greatly appreciated.

 
Not quite, but almost.
The text property of the text control has the dataformat string.
That means that the code you wrote will concatenate the strings to one long string and output it in the Sum-box.

What you want to do is to convert the strings to a format that the '+' operator sums up, instead of concatenates. (That operator does different things, dependant on the format of the data.)

Try this instead:
Code:
txtTotal = CCur(txtCash) + CCur(txtCheck) + CCur(txtMisc)

This will convert the strings to the currency format, that the '+' operator will sum up for you.

Good Luck
-Mats Hulten
 
You sir, are the man...

Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top