[RESOLVED] Adding Numbers Together (you won't believe this)
Normally, if you have numbers in text boxes you can say
Code:
TextBox3.text = STR( val(textbox1.text) + val(textbox2.text))
eg, 5 = 2 + 3
This has been the old faithful simple addition for as long as I can remember
I have suddenly found this does not work, if the text box contains a formatted value - namely
When Textbox1 contains 1,000
Textbox2 contains 2,000
The answer becomes 3 (NOT 3000)
Is there a simple way to deal with this problem, without running REPLACE, for example
PS Why do I have to scroll the screen across to find the SUBMIT NEW THREAD Button
(Is it my browser IE8)
Re: Adding Numbers Together (you won't believe this)
Convert to decimal, or don't allow anything but numbers
Re: Adding Numbers Together (you won't believe this)
Got it
I should use CCur instead of Val
TextBox3.text = STR( CCur(textbox1.text) + CCur(textbox2.text))
(where have the formatting controls for the forum gone)
Re: [RESOLVED] Adding Numbers Together (you won't believe this)
I would also advise using CStr() rather than the old STR() function
CStr() will not add the leading space that STR() places in there.
Val() is dangerous in many cases, it reads the value left to right and stops when it finds a non numeric character
24ZY3 would return 24 if val was used on it even though the string is not a valid number at all.