[RESOLVED] I can't opearte a simple + command...?
This is a bit embarrassing...
I can't manage to add different values together...
My code:
Code:
TextBoxAnswer.Text = TextBox1.Text + TextBox2.Text + TextBox3.Text + TextBox4.Text
I import decimal values from my SQL Server into the TextBoxes 1-4, which works fine. But when I try to add the values together into another textbox the answer is just the values combined like a string...?
The column of the table in the SQL server has a datatype decimal(18, 2)
I have also tried to convert the values in the textboxes into int, str, double... Nothing seems to work...
Need some help here!
Example:
Answer = 2,50 + 2,50 + 5,50 + 4,50
So,
TextBoxAnswer.Text = 10,00
but, all I get is:
2,502,505,504,50
Re: I can't opearte a simple + command...?
Because you are "adding" Strings! You have your decimal values from database, however you put into textboxes (which hold text, or strings).
You have to Re-convert the text to a number, or even better use the original number for the addition!
The Re-Convert would look like that:
Code:
TextBoxAnswer.Text = CDbl(TextBox1.Text) + CDbl(TextBox2.Text) + CDbl(TextBox3.Text) + CDbl(TextBox4.Text)
Re: I can't opearte a simple + command...?
Quote:
Originally Posted by
opus
Because you are "adding" Strings! You have your decimal values from database, however you put into textboxes (which hold text, or strings).
You have to Re-convert the text to a number, or even better use the original number for the addition!
The Re-Convert would look like that:
Code:
TextBoxAnswer.Text = CDbl(TextBox1.Text) + CDbl(TextBox2.Text) + CDbl(TextBox3.Text) + CDbl(TextBox4.Text)
:):):)
Thanks a lot! I appreciate this!
:wave:
Re: I can't opearte a simple + command...?
You might want to be sure beforehand that the values you are adding are really numbers (since textboxes can hold almost anything), using one way or other.
If you intend to add and show the database fields, then use those instead of textbox values, since values in the textboxes can be altered.