PC Review


Reply
Thread Tools Rate Thread

Adding values in text boxes

 
 
David Plotts
Guest
Posts: n/a
 
      2nd Feb 2007
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


 
Reply With Quote
 
 
 
 
rowe_newsgroups
Guest
Posts: n/a
 
      2nd Feb 2007
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

 
Reply With Quote
 
David Plotts
Guest
Posts: n/a
 
      2nd Feb 2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
RobinS
Guest
Posts: n/a
 
      2nd Feb 2007
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>>

>
>



 
Reply With Quote
 
rowe_newsgroups
Guest
Posts: n/a
 
      2nd Feb 2007
> 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.none> wrote:
> 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.com> wrote in message
>
> news:%(E-Mail Removed)...
>
> > 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.com> wrote in message
> >news:(E-Mail Removed)...
> >> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adding up values in text boxes jbennett via AccessMonster.com Microsoft Access Form Coding 4 30th May 2006 07:37 PM
Adding up values in drop down boxes selection kickpoint Microsoft Frontpage 1 17th Jul 2005 12:47 PM
Adding new values to combo boxes (overriding the item not in list =?Utf-8?B?Y2hyaXNt?= Microsoft Access VBA Modules 9 3rd Apr 2005 12:41 AM
Re: text boxes values Sandra Daigle Microsoft Access Forms 0 21st Aug 2003 10:27 AM
text boxes values rathika Microsoft Access Forms 1 20th Aug 2003 04:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:57 AM.