-
Feb 3rd, 2011, 07:11 AM
#1
Thread Starter
Lively Member
[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
-
Feb 3rd, 2011, 07:34 AM
#2
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)
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Feb 3rd, 2011, 07:58 AM
#3
Thread Starter
Lively Member
Re: I can't opearte a simple + command...?
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!
-
Feb 3rd, 2011, 08:32 AM
#4
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.
Tags for this Thread
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
|