473,378 Members | 1,478 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,378 software developers and data experts.

Adding values in text boxes

I'm a beginner with VB.net, only had one class in college on it.

I can't seem to remember how to add text boxes up.

I want to add the values in text boxes together, and put the value into a
label

This is what I have, but it just adds the values together. So if
txt_roads_pre.text has 5, and txt_parking_pre.text has 6,
lbl_impervious_pre.text would have "56"

lbl_impervious_pre.Text = txt_roads_pre.Text + txt_parking_pre.Text +
txt_driveway_pre.Text + txt_sidewalk_pre.Text + txt_building_pre.Text +
txt_decks_pre.Text + txt_pools_ponds_pre.Text + txt_other_pre.Text
Feb 2 '07 #1
4 2971
On Feb 2, 10:15 am, "David Plotts" <dplo...@aesarchitechNOSPAM.com>
wrote:
I'm a beginner with VB.net, only had one class in college on it.

I can't seem to remember how to add text boxes up.

I want to add the values in text boxes together, and put the value into a
label

This is what I have, but it just adds the values together. So if
txt_roads_pre.text has 5, and txt_parking_pre.text has 6,
lbl_impervious_pre.text would have "56"

lbl_impervious_pre.Text = txt_roads_pre.Text + txt_parking_pre.Text +
txt_driveway_pre.Text + txt_sidewalk_pre.Text + txt_building_pre.Text +
txt_decks_pre.Text + txt_pools_ponds_pre.Text + txt_other_pre.Text
You could just wrap them in CInt() or Int32.Parse() or
Convert.ToInt32() etc...

All of the above will convert the Text property of the textbox into a
integer, which then be added together. If using Option Strict On you
will need to convert the sum back to a string to store in the label
though.

i.e.
lbl_impervious_pre.Text = txt_roads_pre.Text + txt_parking_pre.Text + ...
becomes,

lbl_impervious_pre.Text = CStr(CInt(txt_roads_pre.Text) +
CInt(txt_parking_pre.Text) + ... )
Thanks,

Seth Rowe

Feb 2 '07 #2
Great, thanks.

That label only updates with the values when it is clicked on. Is there a
way to have it update as the numbers are changed in the text box?
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
You could just wrap them in CInt() or Int32.Parse() or
Convert.ToInt32() etc...

All of the above will convert the Text property of the textbox into a
integer, which then be added together. If using Option Strict On you
will need to convert the sum back to a string to store in the label
though.

i.e.
>lbl_impervious_pre.Text = txt_roads_pre.Text + txt_parking_pre.Text + ...

becomes,

lbl_impervious_pre.Text = CStr(CInt(txt_roads_pre.Text) +
CInt(txt_parking_pre.Text) + ... )
Thanks,

Seth Rowe

Feb 2 '07 #3
You'd have to capture the Change events for every textbox, which you could
do by adding something like this in your Form_Load event.

AddHandler txt_roads_pre.Changed, AddressOf RecalculateMyNumbers
AddHandler txt_parking_pre.changed, AddressOf RecalculateMyNumbers

and so on, assuming RecalculateMyNumbers is a routine that does what it
says.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
------------------------------------------------
"David Plotts" <dp*****@aesarchitechNOSPAM.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Great, thanks.

That label only updates with the values when it is clicked on. Is there
a way to have it update as the numbers are changed in the text box?
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>You could just wrap them in CInt() or Int32.Parse() or
Convert.ToInt32() etc...

All of the above will convert the Text property of the textbox into a
integer, which then be added together. If using Option Strict On you
will need to convert the sum back to a string to store in the label
though.

i.e.
>>lbl_impervious_pre.Text = txt_roads_pre.Text + txt_parking_pre.Text +
...

becomes,

lbl_impervious_pre.Text = CStr(CInt(txt_roads_pre.Text) +
CInt(txt_parking_pre.Text) + ... )
Thanks,

Seth Rowe


Feb 2 '07 #4
AddHandler txt_roads_pre.Changed, AddressOf RecalculateMyNumbers
AddHandler txt_parking_pre.changed, AddressOf RecalculateMyNumbers
Or just attach the event to the RecalculateMyNumbers method with the
handles keyword (only applicable if the controls are added at design
time)

ie

public sub RecalculateMyNumbers() handles txt_roads_pre.Changed,
txt_parking_pre.Changed, ......

end sub

Both do the same, but the second example is what the designer
generates when you map an event, while the addhandler is used mainly
for dynamic mapping of events (like for dynamically created controls).

Thanks,

Seth Rowe
On Feb 2, 2:00 pm, "RobinS" <Rob...@NoSpam.yah.nonewrote:
You'd have to capture the Change events for every textbox, which you could
do by adding something like this in your Form_Load event.

AddHandler txt_roads_pre.Changed, AddressOf RecalculateMyNumbers
AddHandler txt_parking_pre.changed, AddressOf RecalculateMyNumbers

and so on, assuming RecalculateMyNumbers is a routine that does what it
says.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
------------------------------------------------"David Plotts" <dplo...@aesarchitechNOSPAM.comwrote in message

news:%2****************@TK2MSFTNGP05.phx.gbl...
Great, thanks.
That label only updates with the values when it is clicked on. Is there
a way to have it update as the numbers are changed in the text box?
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
You could just wrap them in CInt() or Int32.Parse() or
Convert.ToInt32() etc...
All of the above will convert the Text property of the textbox into a
integer, which then be added together. If using Option Strict On you
will need to convert the sum back to a string to store in the label
though.
i.e.
>lbl_impervious_pre.Text = txt_roads_pre.Text + txt_parking_pre.Text +
...
becomes,
lbl_impervious_pre.Text = CStr(CInt(txt_roads_pre.Text) +
CInt(txt_parking_pre.Text) + ... )
Thanks,
Seth Rowe

Feb 2 '07 #5

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

Similar topics

1
by: Frank | last post by:
I have a large form, that has text boxes of numbers in rows and columns. I need to sum the values in the columns, and put the total at the bottom of the column. But I also need to sum the values in...
15
by: crjunk | last post by:
I have 4 TextBoxes on my form that I'm trying to add together to get a grand total. Here is the code I'm using: <SCRIPT LANGUAGE="JavaScript"> <!-- Beginning of JavaScript - function...
7
by: Gertjan van Heijst | last post by:
Hi, I really hope someone can help me because I've already spend 2 days on this problem and I'm not getting anywhere. I think the problem is that I don't really understand how text boxes store...
13
by: Shannan Casteel via AccessMonster.com | last post by:
I set up two tables (one with the regular claim info and another with ClaimNumber, PartNumber, and QuantityReplaced). The ClaimNumber is an autonumber and the primary key in both tables. I made a...
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: ballygowanboy | last post by:
i've put this code together. there's a variable "s" giving me some grief at the mo, i'm actualy supprised it half works. it's a simple shopping cart, you pick the quantitly of items, and it...
1
by: cluce | last post by:
I am trying to add only my selected values but its only adding the first selected value in my list repeatedly to the amount of selected items. can someone help me with this? for example, lets say...
1
by: cluce | last post by:
I am trying to add only my selected values but its only adding the first selected value in my list repeatedly to the amount of selected items. can someone help me with this? for example, lets say...
2
by: Canye | last post by:
I have a very long list of codes that i was advised to put in a module but don't know where to start from. Also i have a botton in my software that i what to use to be adding tabs when running my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.