how do you set a text box to keep a running total of a the total value of the numbers in a couple of other text boxes.
Printable View
how do you set a text box to keep a running total of a the total value of the numbers in a couple of other text boxes.
This will keep a word count writing to text1 of how many words are in text2.Code:Text1.text = Len(Text2.text)
And this will add three textboxes together (as the user types) and it will add the result to the fourth textbox
Code:Option Explicit
Private Sub Text2_Change()
Text1 = Val(Text2) + Val(Text3) + Val(Text4)
End Sub
Private Sub Text3_Change()
Text1 = Val(Text2) + Val(Text3) + Val(Text4)
End Sub
Private Sub Text4_Change()
Text1 = Val(Text2) + Val(Text3) + Val(Text4)
End Sub
Oops, didn't see the value part :p. Anyway, what does Val() do?Quote:
adam3000 how do you set a text box to keep a running total of a the total value of the numbers in a couple of other text boxes.
Val() = Returns the numbers contained in a string.
Anyone care to explain more?
Try put this in a immediate window
?val(" 1 2 345 6.7 8,9 hsfg h 56 34")
You'll notice that Val searches for the number's, ignores spaces, stops whenever it finds other characters, only accepts "." as decimal separator
I had just figured that out but wasen't sure if that was the best way to do it. now i know. Thanks.
Quote:
Originally posted by QWERTY
And this will add three textboxes together (as the user types) and it will add the result to the fourth textbox
Code:Option Explicit
Private Sub Text2_Change()
Text1 = Val(Text2) + Val(Text3) + Val(Text4)
End Sub
Private Sub Text3_Change()
Text1 = Val(Text2) + Val(Text3) + Val(Text4)
End Sub
Private Sub Text4_Change()
Text1 = Val(Text2) + Val(Text3) + Val(Text4)
End Sub