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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding currency values 1

Status
Not open for further replies.

obulldog27

Programmer
Apr 26, 2004
169
0
0
US
I need to add 5 textboxes and give the result in one textbox called misctotal.Text. Problem: When I enter a number in one field that same value shows on misctotal.Text NOT the total of all AND then when the focus is lost the misctotal.text changes to zero. All textboxes are set to currency in properties. Whats weird is when I change the dataformat under properties to number then everything adds right but the dataformat of currency does not stay for the textboxes being added. I am using ado control.
---------------------------------------------------------
Private Sub misc_gettotal(textbox)
Dim temp As Variant

Dim tempmisc1 As Variant
Dim tempmisc2 As Variant
Dim tempmisc3 As Variant
Dim tempmisc4 As Variant
Dim tempmisc5 As Variant


tempmisc1 = (misc1.Text)
tempmisc2 = (misc2.Text)
tempmisc3 = (misc3.Text)
tempmisc4 = (misc4.Text)
tempmisc5 = (misc5.Text)


temp = Val(tempmisc1) + Val(tempmisc2) + Val(tempmisc3)+ Val(tempmisc4) + Val(tempmisc5)

misctotal.Text = FormatCurrency(temp)


End Sub
 
If textbox.text = "$1.00" then Val("$1.00") will = 0 because of the $. This is reason your total is 0.

So here are a couple of options.
1) Remove the $ from each textbox before using the Val function

2) Change all of your textboxes to Masked Edit boxes with the Format property set to $#,##0.00;($#,##0.00). Then your current code should work fine.

Hope this helps.
 
I have tried this. I tested using only one text and it works but when I start adding them all I get an invalid procedure call and highlights the second textbox.
---------------------------------------------

Private Sub misc_gettotal(textbox)
Dim temp As Variant
Dim temp2 As Variant

Dim tempmisc1 As Variant
Dim tempmisc2 As Variant
Dim tempmisc3 As Variant
Dim tempmisc4 As Variant
Dim tempmisc5 As Variant


tempmisc1 = (misc1.Text)
tempmisc2 = (misc2.Text)
tempmisc3 = (misc3.Text)
tempmisc4 = (misc4.Text)
tempmisc5 = (misc5.Text)

tempmisc1 = FormatNumber(tempmisc1)
tempmisc2 = FormatNumber(tempmisc2)<-------------
tempmisc3 = FormatNumber(tempmisc3)
tempmisc4 = FormatNumber(tempmisc4)
tempmisc5 = FormatNumber(tempmisc5)

misctotal.Text = Val(tempmisc1) + Val(tempmisc2) + Val(tempmisc3) + Val(tempmisc4) + Val(tempmisc5)
miscg.Text = misctotal.Text


End Sub
 
Try this

tempmisc1 = Format(misc1.Text,"###0.00")
tempmisc2 = Format(misc2.Text,"###0.00")
tempmisc3 = Format(misc3.Text,"###0.00")
tempmisc4 = Format(misc4.Text,"###0.00")
tempmisc5 = Format(misc5.Text,"###0.00")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top