PC Review


Reply
Thread Tools Rate Thread

add total from 6 textboxes and put in label

 
 
pswanie
Guest
Posts: n/a
 
      19th Jan 2008
i got 6 textboxes where users enter amounts. i need the total from those to
display in label24 userform1

would it be posible to default the amount enterd in a text box with the
prefix "R" and "." to seperate sents? we use amounts like R1125.80
 
Reply With Quote
 
 
 
 
Matthew Pfluger
Guest
Posts: n/a
 
      20th Jan 2008
Hello,

Try this:

Sub Example()

' Create variables
Dim dRunningTotal As Double
Dim ctrl As MSForms.ctrlontrol

' Loop through controls looking for text boxes
For Each ctrl In Me.ctrlontrols
If TypeOf ctrl Is MSForms.TextBox Then
' Remove first letter from text box value
dRunningTotal = dRunningTotal + Right(ctrl.Text, Len(ctrl.Text)
- 1)
End If
Next ctrl

' Copy total to label
Me.label24.Value = dRunningTotal

End Sub

HTH,
Matthew Pfluger

"pswanie" wrote:

> i got 6 textboxes where users enter amounts. i need the total from those to
> display in label24 userform1
>
> would it be posible to default the amount enterd in a text box with the
> prefix "R" and "." to seperate sents? we use amounts like R1125.80

 
Reply With Quote
 
pswanie
Guest
Posts: n/a
 
      20th Jan 2008
i got about 20 textboxes and need one set of 6 to sumtotal to label1
another 5 sumtotal to label2
and 3 to sumtotal to label3

"Matthew Pfluger" wrote:

> Hello,
>
> Try this:
>
> Sub Example()
>
> ' Create variables
> Dim dRunningTotal As Double
> Dim ctrl As MSForms.ctrlontrol
>
> ' Loop through controls looking for text boxes
> For Each ctrl In Me.ctrlontrols
> If TypeOf ctrl Is MSForms.TextBox Then
> ' Remove first letter from text box value
> dRunningTotal = dRunningTotal + Right(ctrl.Text, Len(ctrl.Text)
> - 1)
> End If
> Next ctrl
>
> ' Copy total to label
> Me.label24.Value = dRunningTotal
>
> End Sub
>
> HTH,
> Matthew Pfluger
>
> "pswanie" wrote:
>
> > i got 6 textboxes where users enter amounts. i need the total from those to
> > display in label24 userform1
> >
> > would it be posible to default the amount enterd in a text box with the
> > prefix "R" and "." to seperate sents? we use amounts like R1125.80

 
Reply With Quote
 
Matthew Pfluger
Guest
Posts: n/a
 
      20th Jan 2008
The best solution here is to rename your textboxes with a little prefix like
this:
"grp1TextBoxName"
Then you can run 1 loop that adds up textbox values based on that prefix:

Sub Example()

' Create variables
Dim dSum1 As Double
Dim dSum2 As Double
Dim dSum3 As Double
Dim ctrl As MSForms.Control

' Loop through controls looking for text boxes
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
If InStr(ctrl.Name, "grp1") <> 0 Then
' Add to group 1 total

' Remove first letter from text box value
dSum1 = dSum1 + Right(ctrl.Text, Len(ctrl.Text) - 1)
ElseIf InStr(ctrl.Name, "grp2") <> 0 Then
' Add to group 2 total

' Remove first letter from text box value
dSum2 = dSum2 + Right(ctrl.Text, Len(ctrl.Text) - 1)
ElseIf InStr(ctrl.Name, "grp3") <> 0 Then
' Add to group 2 total

' Remove first letter from text box value
dSum3 = dSum3 + Right(ctrl.Text, Len(ctrl.Text) - 1)
End If
End If
Next ctrl

' Copy totals to labels
With Me
.label1.Value = dSum1
.label2.Value = dSum2
.label3.Value = dSum3
End With

End Sub

The code finds all textboxes, checks their name for either "grp1", "grp2",
or "grp3", and then adds up totals based on that naming convention.

Hope this helps,
Matthew Pfluger

"pswanie" wrote:

> i got about 20 textboxes and need one set of 6 to sumtotal to label1
> another 5 sumtotal to label2
> and 3 to sumtotal to label3
>
> "Matthew Pfluger" wrote:
>
> > Hello,
> >
> > Try this:
> >
> > Sub Example()
> >
> > ' Create variables
> > Dim dRunningTotal As Double
> > Dim ctrl As MSForms.ctrlontrol
> >
> > ' Loop through controls looking for text boxes
> > For Each ctrl In Me.ctrlontrols
> > If TypeOf ctrl Is MSForms.TextBox Then
> > ' Remove first letter from text box value
> > dRunningTotal = dRunningTotal + Right(ctrl.Text, Len(ctrl.Text)
> > - 1)
> > End If
> > Next ctrl
> >
> > ' Copy total to label
> > Me.label24.Value = dRunningTotal
> >
> > End Sub
> >
> > HTH,
> > Matthew Pfluger
> >
> > "pswanie" wrote:
> >
> > > i got 6 textboxes where users enter amounts. i need the total from those to
> > > display in label24 userform1
> > >
> > > would it be posible to default the amount enterd in a text box with the
> > > prefix "R" and "." to seperate sents? we use amounts like R1125.80

 
Reply With Quote
 
pswanie
Guest
Posts: n/a
 
      20th Jan 2008
will give that a try and let u know. in the meanwhile i started thinking if
i shouldnt rather have only one textbox and a combobox.

the textbox the can enter the amount and the combo box will give the cashier
name.

and let it all add to a cell on sheet1 depending on the name. ie. anna colum
a and mari colum b and john colum c

and have the lable go and get the total from there.

will let u know


thanx

"Matthew Pfluger" wrote:

> The best solution here is to rename your textboxes with a little prefix like
> this:
> "grp1TextBoxName"
> Then you can run 1 loop that adds up textbox values based on that prefix:
>
> Sub Example()
>
> ' Create variables
> Dim dSum1 As Double
> Dim dSum2 As Double
> Dim dSum3 As Double
> Dim ctrl As MSForms.Control
>
> ' Loop through controls looking for text boxes
> For Each ctrl In Me.Controls
> If TypeOf ctrl Is MSForms.TextBox Then
> If InStr(ctrl.Name, "grp1") <> 0 Then
> ' Add to group 1 total
>
> ' Remove first letter from text box value
> dSum1 = dSum1 + Right(ctrl.Text, Len(ctrl.Text) - 1)
> ElseIf InStr(ctrl.Name, "grp2") <> 0 Then
> ' Add to group 2 total
>
> ' Remove first letter from text box value
> dSum2 = dSum2 + Right(ctrl.Text, Len(ctrl.Text) - 1)
> ElseIf InStr(ctrl.Name, "grp3") <> 0 Then
> ' Add to group 2 total
>
> ' Remove first letter from text box value
> dSum3 = dSum3 + Right(ctrl.Text, Len(ctrl.Text) - 1)
> End If
> End If
> Next ctrl
>
> ' Copy totals to labels
> With Me
> .label1.Value = dSum1
> .label2.Value = dSum2
> .label3.Value = dSum3
> End With
>
> End Sub
>
> The code finds all textboxes, checks their name for either "grp1", "grp2",
> or "grp3", and then adds up totals based on that naming convention.
>
> Hope this helps,
> Matthew Pfluger
>
> "pswanie" wrote:
>
> > i got about 20 textboxes and need one set of 6 to sumtotal to label1
> > another 5 sumtotal to label2
> > and 3 to sumtotal to label3
> >
> > "Matthew Pfluger" wrote:
> >
> > > Hello,
> > >
> > > Try this:
> > >
> > > Sub Example()
> > >
> > > ' Create variables
> > > Dim dRunningTotal As Double
> > > Dim ctrl As MSForms.ctrlontrol
> > >
> > > ' Loop through controls looking for text boxes
> > > For Each ctrl In Me.ctrlontrols
> > > If TypeOf ctrl Is MSForms.TextBox Then
> > > ' Remove first letter from text box value
> > > dRunningTotal = dRunningTotal + Right(ctrl.Text, Len(ctrl.Text)
> > > - 1)
> > > End If
> > > Next ctrl
> > >
> > > ' Copy total to label
> > > Me.label24.Value = dRunningTotal
> > >
> > > End Sub
> > >
> > > HTH,
> > > Matthew Pfluger
> > >
> > > "pswanie" wrote:
> > >
> > > > i got 6 textboxes where users enter amounts. i need the total from those to
> > > > display in label24 userform1
> > > >
> > > > would it be posible to default the amount enterd in a text box with the
> > > > prefix "R" and "." to seperate sents? we use amounts like R1125.80

 
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 textboxes based on what user inputs in Total Students textb sam Microsoft Excel Programming 0 29th Jan 2010 05:46 PM
Getting the total of the records in a label Nicola M Microsoft Access Form Coding 2 4th Mar 2009 10:16 PM
Dynamic WinForms Label & Textboxes =?Utf-8?B?UGF0cmljaw==?= Microsoft Dot NET Framework Forms 5 31st Aug 2007 07:27 PM
About using repeater control with textboxes and label in the client side Neo Microsoft ASP .NET 0 22nd Mar 2006 09:36 AM
add up and calculate textboxes into a label Peter Microsoft Excel Programming 0 15th Sep 2005 05:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:38 AM.