473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sum of Multiple Text Boxes

I am trying to add the text of several textboxes as a sum
using the + sign but even converting to integer it is
concatenating. Any help would be greatly appreciated.

Dim price1 As Integer

Dim price2 As Integer

Dim price3 As Integer

Dim price4 As Integer

Dim price5 As Integer

Dim TotalPrice As Integer

price1 = CType(txtcost1.Text, Integer)

price2 = CType(txtcost2.Text, Integer)

price3 = CType(txtcost3.Text, Integer)

price4 = CType(txtcost4.Text, Integer)

price5 = CType(txtcost5.Text, Integer)

TotalPrice = price1 + price2 + price3 + price4 +
price5

txtEC.Text = TotalPrice

ShowFields()
Jul 21 '05 #1
3 2223
Derek:

I just copied your code onto a form and added the five textboxes. I
commented out ShowFields because I don't know what that does. It works
fine. Being that everything here is an int, I'm inclined to think something
else is the problem. you could also try price1.Parse(txtcost1.text) etc but
Ints are going to add not concatenate.

If you debug.WriteLine after the TotalPrice line,
Debug.WriteLine(TotalPrice.ToString), what number do you get?

Also, if any of those text boxes contain nonnumeric data or are empty,
you're going to have some drama, so make sure you don't let the user hit the
Calc button until all the info is good.

Post the rest of the code block, we can figure this one out.

HTH,

Bill

HTH,

Bill
"Derek" <de**********@charleston.af.mil> wrote in message
news:63****************************@phx.gbl...
I am trying to add the text of several textboxes as a sum
using the + sign but even converting to integer it is
concatenating. Any help would be greatly appreciated.

Dim price1 As Integer

Dim price2 As Integer

Dim price3 As Integer

Dim price4 As Integer

Dim price5 As Integer

Dim TotalPrice As Integer

price1 = CType(txtcost1.Text, Integer)

price2 = CType(txtcost2.Text, Integer)

price3 = CType(txtcost3.Text, Integer)

price4 = CType(txtcost4.Text, Integer)

price5 = CType(txtcost5.Text, Integer)

TotalPrice = price1 + price2 + price3 + price4 +
price5

txtEC.Text = TotalPrice

ShowFields()

Jul 21 '05 #2

What you said about empty strings etc. was right. I was adding the 5th
textbox in code but not showing it to input data.
Thanks so much!

Derek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
What you said about empty strings etc. was right. I was
adding the 5th
textbox in code but not showing it to input data.
Thanks so much!

Derek

-----Original Message-----
Derek:

I just copied your code onto a form and added the five textboxes. Icommented out ShowFields because I don't know what that does. It worksfine. Being that everything here is an int, I'm inclined to think somethingelse is the problem. you could also try price1.Parse (txtcost1.text) etc butInts are going to add not concatenate.

If you debug.WriteLine after the TotalPrice line,
Debug.WriteLine(TotalPrice.ToString), what number do you get?
Also, if any of those text boxes contain nonnumeric data or are empty,you're going to have some drama, so make sure you don't let the user hit theCalc button until all the info is good.

Post the rest of the code block, we can figure this one out.
HTH,

Bill

HTH,

Bill
"Derek" <de**********@charleston.af.mil> wrote in message
news:63****************************@phx.gbl...
I am trying to add the text of several textboxes as a sum using the + sign but even converting to integer it is
concatenating. Any help would be greatly appreciated.

Dim price1 As Integer

Dim price2 As Integer

Dim price3 As Integer

Dim price4 As Integer

Dim price5 As Integer

Dim TotalPrice As Integer

price1 = CType(txtcost1.Text, Integer)

price2 = CType(txtcost2.Text, Integer)

price3 = CType(txtcost3.Text, Integer)

price4 = CType(txtcost4.Text, Integer)

price5 = CType(txtcost5.Text, Integer)

TotalPrice = price1 + price2 + price3 + price4 +
price5

txtEC.Text = TotalPrice

ShowFields()

.

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
2
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another...
1
by: Frustrated Developer via DotNetMonster.com | last post by:
I have developed a form that would allow the user to load and search a database several ways, by data range using two combo boxes, by specific number entered in a text box or all database entries....
1
by: Shawn Yates | last post by:
It has been a while since I have done anything on MS Access and I seem to be a bit rusty. I hope someone could help me solve my issue. I have a form that has multiple combo boxes on it. Each box...
4
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I...
4
neo008
by: neo008 | last post by:
Hi all, Finally gave up and putting it here. I am new to visual basic stucked up with an error- Run time errors.'-2147217887 (8004021)': Multiple-step operation generated errors. check each...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.