-
February 26th, 2014, 10:51 PM
#1
[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)
-
February 26th, 2014, 10:54 PM
#2
Re: Adding Numbers Together (you won't believe this)
Convert to decimal, or don't allow anything but numbers
-
February 26th, 2014, 11:05 PM
#3
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)
-
February 27th, 2014, 02:11 AM
#4
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.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|