PC Review


Reply
Thread Tools Rate Thread

Computing Average

 
 
Bishop
Guest
Posts: n/a
 
      25th Jun 2009

I have 10 textboxes that will contain values from 1-5. Not all the textboxes
HAVE to contain a value, though. How do I write code that will consider all
10 textboxes and give me the average of only the textboxes with values in
them?

For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
average should show 4. But the next time boxes 1,3,5,7,9 have values
2,4,5,3,5 respectively. The average should show 3.8.
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      25th Jun 2009

If the textboxes are named TextBox1, TextBox2 etc;... try something like the
below

Dim varSum As Long, varCount As Long
For intTemp = 1 To 10
If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
varCount = varCount + 1
End If
Next
MsgBox "Average :" & (varSum / varCount)


If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

> I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> HAVE to contain a value, though. How do I write code that will consider all
> 10 textboxes and give me the average of only the textboxes with values in
> them?
>
> For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> average should show 4. But the next time boxes 1,3,5,7,9 have values
> 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
Bishop
Guest
Posts: n/a
 
      25th Jun 2009

I see what you're doing but my textboxes all have specific names like
PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
other text boxes in the userform besides those that won't be used in the
average calculation. How would I set it up so that just these specific
textboxes are used for the calculation?

"Jacob Skaria" wrote:

> If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> below
>
> Dim varSum As Long, varCount As Long
> For intTemp = 1 To 10
> If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> varCount = varCount + 1
> End If
> Next
> MsgBox "Average :" & (varSum / varCount)
>
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Bishop" wrote:
>
> > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > HAVE to contain a value, though. How do I write code that will consider all
> > 10 textboxes and give me the average of only the textboxes with values in
> > them?
> >
> > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
EricG
Guest
Posts: n/a
 
      25th Jun 2009

Dim myBoxes(10) as String
'
myBoxes(1) = "PlotTextBox"
myBoxes(2) = "PaceTextBox"
myBoxes(3) = "ActingTextBox"
etc...
(whatever your textbox names are)

Then in his loop, change "Textbox" & intTemp to myBoxes(intTemp)

HTH,

Eric

"Bishop" wrote:

> I see what you're doing but my textboxes all have specific names like
> PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
> other text boxes in the userform besides those that won't be used in the
> average calculation. How would I set it up so that just these specific
> textboxes are used for the calculation?
>
> "Jacob Skaria" wrote:
>
> > If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> > below
> >
> > Dim varSum As Long, varCount As Long
> > For intTemp = 1 To 10
> > If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> > varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> > varCount = varCount + 1
> > End If
> > Next
> > MsgBox "Average :" & (varSum / varCount)
> >
> >
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "Bishop" wrote:
> >
> > > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > > HAVE to contain a value, though. How do I write code that will consider all
> > > 10 textboxes and give me the average of only the textboxes with values in
> > > them?
> > >
> > > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > > 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
Bishop
Guest
Posts: n/a
 
      25th Jun 2009

I'm doing something wrong. Here's what I have:

Dim ScoreBox(18) As String
ScoreBox(1) = "ActingTextBox"
ScoreBox(2) = "ActionTextBox"
ScoreBox(3) = "ComedyTextBox"
ScoreBox(4) = "DialogTextBox"
..
..
..

Dim varSum As Long, varCount As Long, ScoringAve As Long
Dim i As Integer
For i = 1 To 18
If Trim(Me.Controls(ScoreBox(i).Value)) <> "" Then
varSum = varSum + ("0" & Me.Controls(ScoreBox(i).Value))
varCount = varCount + 1
End If
Next
ScoringAve = (varCount / varSum)

I'm getting Invalid Qualifier on ScoreBox in the If statement.

"EricG" wrote:

> Dim myBoxes(10) as String
> '
> myBoxes(1) = "PlotTextBox"
> myBoxes(2) = "PaceTextBox"
> myBoxes(3) = "ActingTextBox"
> etc...
> (whatever your textbox names are)
>
> Then in his loop, change "Textbox" & intTemp to myBoxes(intTemp)
>
> HTH,
>
> Eric
>
> "Bishop" wrote:
>
> > I see what you're doing but my textboxes all have specific names like
> > PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
> > other text boxes in the userform besides those that won't be used in the
> > average calculation. How would I set it up so that just these specific
> > textboxes are used for the calculation?
> >
> > "Jacob Skaria" wrote:
> >
> > > If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> > > below
> > >
> > > Dim varSum As Long, varCount As Long
> > > For intTemp = 1 To 10
> > > If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> > > varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> > > varCount = varCount + 1
> > > End If
> > > Next
> > > MsgBox "Average :" & (varSum / varCount)
> > >
> > >
> > > If this post helps click Yes
> > > ---------------
> > > Jacob Skaria
> > >
> > >
> > > "Bishop" wrote:
> > >
> > > > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > > > HAVE to contain a value, though. How do I write code that will consider all
> > > > 10 textboxes and give me the average of only the textboxes with values in
> > > > them?
> > > >
> > > > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > > > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > > > 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
Sam Wilson
Guest
Posts: n/a
 
      25th Jun 2009

You want scorebox(i), not scorebox(i).value

Sam

"Bishop" wrote:

> I'm doing something wrong. Here's what I have:
>
> Dim ScoreBox(18) As String
> ScoreBox(1) = "ActingTextBox"
> ScoreBox(2) = "ActionTextBox"
> ScoreBox(3) = "ComedyTextBox"
> ScoreBox(4) = "DialogTextBox"
> .
> .
> .
>
> Dim varSum As Long, varCount As Long, ScoringAve As Long
> Dim i As Integer
> For i = 1 To 18
> If Trim(Me.Controls(ScoreBox(i).Value)) <> "" Then
> varSum = varSum + ("0" & Me.Controls(ScoreBox(i).Value))
> varCount = varCount + 1
> End If
> Next
> ScoringAve = (varCount / varSum)
>
> I'm getting Invalid Qualifier on ScoreBox in the If statement.
>
> "EricG" wrote:
>
> > Dim myBoxes(10) as String
> > '
> > myBoxes(1) = "PlotTextBox"
> > myBoxes(2) = "PaceTextBox"
> > myBoxes(3) = "ActingTextBox"
> > etc...
> > (whatever your textbox names are)
> >
> > Then in his loop, change "Textbox" & intTemp to myBoxes(intTemp)
> >
> > HTH,
> >
> > Eric
> >
> > "Bishop" wrote:
> >
> > > I see what you're doing but my textboxes all have specific names like
> > > PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
> > > other text boxes in the userform besides those that won't be used in the
> > > average calculation. How would I set it up so that just these specific
> > > textboxes are used for the calculation?
> > >
> > > "Jacob Skaria" wrote:
> > >
> > > > If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> > > > below
> > > >
> > > > Dim varSum As Long, varCount As Long
> > > > For intTemp = 1 To 10
> > > > If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> > > > varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> > > > varCount = varCount + 1
> > > > End If
> > > > Next
> > > > MsgBox "Average :" & (varSum / varCount)
> > > >
> > > >
> > > > If this post helps click Yes
> > > > ---------------
> > > > Jacob Skaria
> > > >
> > > >
> > > > "Bishop" wrote:
> > > >
> > > > > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > > > > HAVE to contain a value, though. How do I write code that will consider all
> > > > > 10 textboxes and give me the average of only the textboxes with values in
> > > > > them?
> > > > >
> > > > > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > > > > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > > > > 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
EricG
Guest
Posts: n/a
 
      25th Jun 2009

You have a parenthesis problem in two places.

Instead of:

Me.Controls(ScoreBox(i).Value)

It should be:

Me.Controls(ScoreBox(i)).Value
--
-------------------
If toast always lands butter-side down, and cats always land on their feet,
what happen if you strap toast on the back of a cat and drop it?
Steven Wright (1955 - )


"Bishop" wrote:

> I'm doing something wrong. Here's what I have:
>
> Dim ScoreBox(18) As String
> ScoreBox(1) = "ActingTextBox"
> ScoreBox(2) = "ActionTextBox"
> ScoreBox(3) = "ComedyTextBox"
> ScoreBox(4) = "DialogTextBox"
> .
> .
> .
>
> Dim varSum As Long, varCount As Long, ScoringAve As Long
> Dim i As Integer
> For i = 1 To 18
> If Trim(Me.Controls(ScoreBox(i).Value)) <> "" Then
> varSum = varSum + ("0" & Me.Controls(ScoreBox(i).Value))
> varCount = varCount + 1
> End If
> Next
> ScoringAve = (varCount / varSum)
>
> I'm getting Invalid Qualifier on ScoreBox in the If statement.
>
> "EricG" wrote:
>
> > Dim myBoxes(10) as String
> > '
> > myBoxes(1) = "PlotTextBox"
> > myBoxes(2) = "PaceTextBox"
> > myBoxes(3) = "ActingTextBox"
> > etc...
> > (whatever your textbox names are)
> >
> > Then in his loop, change "Textbox" & intTemp to myBoxes(intTemp)
> >
> > HTH,
> >
> > Eric
> >
> > "Bishop" wrote:
> >
> > > I see what you're doing but my textboxes all have specific names like
> > > PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
> > > other text boxes in the userform besides those that won't be used in the
> > > average calculation. How would I set it up so that just these specific
> > > textboxes are used for the calculation?
> > >
> > > "Jacob Skaria" wrote:
> > >
> > > > If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> > > > below
> > > >
> > > > Dim varSum As Long, varCount As Long
> > > > For intTemp = 1 To 10
> > > > If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> > > > varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> > > > varCount = varCount + 1
> > > > End If
> > > > Next
> > > > MsgBox "Average :" & (varSum / varCount)
> > > >
> > > >
> > > > If this post helps click Yes
> > > > ---------------
> > > > Jacob Skaria
> > > >
> > > >
> > > > "Bishop" wrote:
> > > >
> > > > > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > > > > HAVE to contain a value, though. How do I write code that will consider all
> > > > > 10 textboxes and give me the average of only the textboxes with values in
> > > > > them?
> > > > >
> > > > > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > > > > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > > > > 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
Bishop
Guest
Posts: n/a
 
      25th Jun 2009

Ok, really frustrated I can't make this work. I read the help file on Trim
and I don't think I need that. I just want to get an average of the values
(integers from 1-5) in the textboxes. This is what I have now:

Dim ScoreBox(18) As String
ScoreBox(1) = "ActingTextBox"
ScoreBox(2) = "ActionTextBox"
ScoreBox(3) = "ComedyTextBox"
ScoreBox(4) = "DialogTextBox"
..
..
..

Dim varSum As Long, varCount As Long, ScoringAve As Long
Dim i As Integer
For i = 1 To 18
If ScoreBox(i).Value <> "" Then
varSum = varSum + ScoreBox(i).Value
varCount = varCount + 1
End If
Next
ScoringAve = (varSum / varCount)

I keep getting Invalid Qualifier for SccoreBox. If i = 1 then
ScoreBox(i).Value should read the same as ActingTextBox.Value, right? And if
varSum is a Long and ActingTextBox.Value is an Integer they should be
compatible, right? Why won't this work?!

"Sam Wilson" wrote:

> You want scorebox(i), not scorebox(i).value
>
> Sam
>
> "Bishop" wrote:
>
> > I'm doing something wrong. Here's what I have:
> >
> > Dim ScoreBox(18) As String
> > ScoreBox(1) = "ActingTextBox"
> > ScoreBox(2) = "ActionTextBox"
> > ScoreBox(3) = "ComedyTextBox"
> > ScoreBox(4) = "DialogTextBox"
> > .
> > .
> > .
> >
> > Dim varSum As Long, varCount As Long, ScoringAve As Long
> > Dim i As Integer
> > For i = 1 To 18
> > If Trim(Me.Controls(ScoreBox(i).Value)) <> "" Then
> > varSum = varSum + ("0" & Me.Controls(ScoreBox(i).Value))
> > varCount = varCount + 1
> > End If
> > Next
> > ScoringAve = (varCount / varSum)
> >
> > I'm getting Invalid Qualifier on ScoreBox in the If statement.
> >
> > "EricG" wrote:
> >
> > > Dim myBoxes(10) as String
> > > '
> > > myBoxes(1) = "PlotTextBox"
> > > myBoxes(2) = "PaceTextBox"
> > > myBoxes(3) = "ActingTextBox"
> > > etc...
> > > (whatever your textbox names are)
> > >
> > > Then in his loop, change "Textbox" & intTemp to myBoxes(intTemp)
> > >
> > > HTH,
> > >
> > > Eric
> > >
> > > "Bishop" wrote:
> > >
> > > > I see what you're doing but my textboxes all have specific names like
> > > > PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
> > > > other text boxes in the userform besides those that won't be used in the
> > > > average calculation. How would I set it up so that just these specific
> > > > textboxes are used for the calculation?
> > > >
> > > > "Jacob Skaria" wrote:
> > > >
> > > > > If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> > > > > below
> > > > >
> > > > > Dim varSum As Long, varCount As Long
> > > > > For intTemp = 1 To 10
> > > > > If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> > > > > varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> > > > > varCount = varCount + 1
> > > > > End If
> > > > > Next
> > > > > MsgBox "Average :" & (varSum / varCount)
> > > > >
> > > > >
> > > > > If this post helps click Yes
> > > > > ---------------
> > > > > Jacob Skaria
> > > > >
> > > > >
> > > > > "Bishop" wrote:
> > > > >
> > > > > > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > > > > > HAVE to contain a value, though. How do I write code that will consider all
> > > > > > 10 textboxes and give me the average of only the textboxes with values in
> > > > > > them?
> > > > > >
> > > > > > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > > > > > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > > > > > 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
Sam Wilson
Guest
Posts: n/a
 
      25th Jun 2009

scorebox(i) is a text string, not the text box object.

it should be
me.controls(scorebox(i)).value

you had
me.controls(scorebox(i).value)

which is different - scorebox(i) doesn't have any properties, so the .value
threw up the invalid qualifier error when placed inside the bracket.

"Bishop" wrote:

> Ok, really frustrated I can't make this work. I read the help file on Trim
> and I don't think I need that. I just want to get an average of the values
> (integers from 1-5) in the textboxes. This is what I have now:
>
> Dim ScoreBox(18) As String
> ScoreBox(1) = "ActingTextBox"
> ScoreBox(2) = "ActionTextBox"
> ScoreBox(3) = "ComedyTextBox"
> ScoreBox(4) = "DialogTextBox"
> .
> .
> .
>
> Dim varSum As Long, varCount As Long, ScoringAve As Long
> Dim i As Integer
> For i = 1 To 18
> If ScoreBox(i).Value <> "" Then
> varSum = varSum + ScoreBox(i).Value
> varCount = varCount + 1
> End If
> Next
> ScoringAve = (varSum / varCount)
>
> I keep getting Invalid Qualifier for SccoreBox. If i = 1 then
> ScoreBox(i).Value should read the same as ActingTextBox.Value, right? And if
> varSum is a Long and ActingTextBox.Value is an Integer they should be
> compatible, right? Why won't this work?!
>
> "Sam Wilson" wrote:
>
> > You want scorebox(i), not scorebox(i).value
> >
> > Sam
> >
> > "Bishop" wrote:
> >
> > > I'm doing something wrong. Here's what I have:
> > >
> > > Dim ScoreBox(18) As String
> > > ScoreBox(1) = "ActingTextBox"
> > > ScoreBox(2) = "ActionTextBox"
> > > ScoreBox(3) = "ComedyTextBox"
> > > ScoreBox(4) = "DialogTextBox"
> > > .
> > > .
> > > .
> > >
> > > Dim varSum As Long, varCount As Long, ScoringAve As Long
> > > Dim i As Integer
> > > For i = 1 To 18
> > > If Trim(Me.Controls(ScoreBox(i).Value)) <> "" Then
> > > varSum = varSum + ("0" & Me.Controls(ScoreBox(i).Value))
> > > varCount = varCount + 1
> > > End If
> > > Next
> > > ScoringAve = (varCount / varSum)
> > >
> > > I'm getting Invalid Qualifier on ScoreBox in the If statement.
> > >
> > > "EricG" wrote:
> > >
> > > > Dim myBoxes(10) as String
> > > > '
> > > > myBoxes(1) = "PlotTextBox"
> > > > myBoxes(2) = "PaceTextBox"
> > > > myBoxes(3) = "ActingTextBox"
> > > > etc...
> > > > (whatever your textbox names are)
> > > >
> > > > Then in his loop, change "Textbox" & intTemp to myBoxes(intTemp)
> > > >
> > > > HTH,
> > > >
> > > > Eric
> > > >
> > > > "Bishop" wrote:
> > > >
> > > > > I see what you're doing but my textboxes all have specific names like
> > > > > PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
> > > > > other text boxes in the userform besides those that won't be used in the
> > > > > average calculation. How would I set it up so that just these specific
> > > > > textboxes are used for the calculation?
> > > > >
> > > > > "Jacob Skaria" wrote:
> > > > >
> > > > > > If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> > > > > > below
> > > > > >
> > > > > > Dim varSum As Long, varCount As Long
> > > > > > For intTemp = 1 To 10
> > > > > > If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> > > > > > varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> > > > > > varCount = varCount + 1
> > > > > > End If
> > > > > > Next
> > > > > > MsgBox "Average :" & (varSum / varCount)
> > > > > >
> > > > > >
> > > > > > If this post helps click Yes
> > > > > > ---------------
> > > > > > Jacob Skaria
> > > > > >
> > > > > >
> > > > > > "Bishop" wrote:
> > > > > >
> > > > > > > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > > > > > > HAVE to contain a value, though. How do I write code that will consider all
> > > > > > > 10 textboxes and give me the average of only the textboxes with values in
> > > > > > > them?
> > > > > > >
> > > > > > > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > > > > > > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > > > > > > 2,4,5,3,5 respectively. The average should show 3.8.

 
Reply With Quote
 
Bishop
Guest
Posts: n/a
 
      25th Jun 2009

Getting Invalid Argument now. I probably should have mentioned this before
but all of this is in a With statement. I have the following code:

With Sheets("Movies")
..
..
..
Dim ScoreBox(18) As String
ScoreBox(1) = "ActingTextBox"
ScoreBox(2) = "ActionTextBox"
ScoreBox(3) = "ComedyTextBox"
ScoreBox(4) = "DialogTextBox"
..
..
..

Dim varSum As Long, varCount As Long, ScoringAve As Long
Dim i As Integer
For i = 1 To 18
If Me.Controls(ScoreBox(i)).Value <> "" Then
varSum = varSum + Me.Controls(ScoreBox(i)).Value
varCount = varCount + 1
End If
Next
ScoringAve = (varSum / varCount)

I tried putting .Me but that didn't work either.

"Sam Wilson" wrote:

> scorebox(i) is a text string, not the text box object.
>
> it should be
> me.controls(scorebox(i)).value
>
> you had
> me.controls(scorebox(i).value)
>
> which is different - scorebox(i) doesn't have any properties, so the .value
> threw up the invalid qualifier error when placed inside the bracket.
>
> "Bishop" wrote:
>
> > Ok, really frustrated I can't make this work. I read the help file on Trim
> > and I don't think I need that. I just want to get an average of the values
> > (integers from 1-5) in the textboxes. This is what I have now:
> >
> > Dim ScoreBox(18) As String
> > ScoreBox(1) = "ActingTextBox"
> > ScoreBox(2) = "ActionTextBox"
> > ScoreBox(3) = "ComedyTextBox"
> > ScoreBox(4) = "DialogTextBox"
> > .
> > .
> > .
> >
> > Dim varSum As Long, varCount As Long, ScoringAve As Long
> > Dim i As Integer
> > For i = 1 To 18
> > If ScoreBox(i).Value <> "" Then
> > varSum = varSum + ScoreBox(i).Value
> > varCount = varCount + 1
> > End If
> > Next
> > ScoringAve = (varSum / varCount)
> >
> > I keep getting Invalid Qualifier for SccoreBox. If i = 1 then
> > ScoreBox(i).Value should read the same as ActingTextBox.Value, right? And if
> > varSum is a Long and ActingTextBox.Value is an Integer they should be
> > compatible, right? Why won't this work?!
> >
> > "Sam Wilson" wrote:
> >
> > > You want scorebox(i), not scorebox(i).value
> > >
> > > Sam
> > >
> > > "Bishop" wrote:
> > >
> > > > I'm doing something wrong. Here's what I have:
> > > >
> > > > Dim ScoreBox(18) As String
> > > > ScoreBox(1) = "ActingTextBox"
> > > > ScoreBox(2) = "ActionTextBox"
> > > > ScoreBox(3) = "ComedyTextBox"
> > > > ScoreBox(4) = "DialogTextBox"
> > > > .
> > > > .
> > > > .
> > > >
> > > > Dim varSum As Long, varCount As Long, ScoringAve As Long
> > > > Dim i As Integer
> > > > For i = 1 To 18
> > > > If Trim(Me.Controls(ScoreBox(i).Value)) <> "" Then
> > > > varSum = varSum + ("0" & Me.Controls(ScoreBox(i).Value))
> > > > varCount = varCount + 1
> > > > End If
> > > > Next
> > > > ScoringAve = (varCount / varSum)
> > > >
> > > > I'm getting Invalid Qualifier on ScoreBox in the If statement.
> > > >
> > > > "EricG" wrote:
> > > >
> > > > > Dim myBoxes(10) as String
> > > > > '
> > > > > myBoxes(1) = "PlotTextBox"
> > > > > myBoxes(2) = "PaceTextBox"
> > > > > myBoxes(3) = "ActingTextBox"
> > > > > etc...
> > > > > (whatever your textbox names are)
> > > > >
> > > > > Then in his loop, change "Textbox" & intTemp to myBoxes(intTemp)
> > > > >
> > > > > HTH,
> > > > >
> > > > > Eric
> > > > >
> > > > > "Bishop" wrote:
> > > > >
> > > > > > I see what you're doing but my textboxes all have specific names like
> > > > > > PlotTextBox, PaceTextBox, ActingTextBox, StoryTextBox, etc. and there are
> > > > > > other text boxes in the userform besides those that won't be used in the
> > > > > > average calculation. How would I set it up so that just these specific
> > > > > > textboxes are used for the calculation?
> > > > > >
> > > > > > "Jacob Skaria" wrote:
> > > > > >
> > > > > > > If the textboxes are named TextBox1, TextBox2 etc;... try something like the
> > > > > > > below
> > > > > > >
> > > > > > > Dim varSum As Long, varCount As Long
> > > > > > > For intTemp = 1 To 10
> > > > > > > If Trim(Me.Controls("Textbox" & intTemp)) <> "" Then
> > > > > > > varSum = varSum + ("0" & Me.Controls("Textbox" & intTemp))
> > > > > > > varCount = varCount + 1
> > > > > > > End If
> > > > > > > Next
> > > > > > > MsgBox "Average :" & (varSum / varCount)
> > > > > > >
> > > > > > >
> > > > > > > If this post helps click Yes
> > > > > > > ---------------
> > > > > > > Jacob Skaria
> > > > > > >
> > > > > > >
> > > > > > > "Bishop" wrote:
> > > > > > >
> > > > > > > > I have 10 textboxes that will contain values from 1-5. Not all the textboxes
> > > > > > > > HAVE to contain a value, though. How do I write code that will consider all
> > > > > > > > 10 textboxes and give me the average of only the textboxes with values in
> > > > > > > > them?
> > > > > > > >
> > > > > > > > For example, say boxes 1,2,3,4,5 have values of 4,5,3,4,4 respectively. The
> > > > > > > > average should show 4. But the next time boxes 1,3,5,7,9 have values
> > > > > > > > 2,4,5,3,5 respectively. The average should show 3.8.

 
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
Error Handling #N/A with AVERAGE Function - Average of values in Row Sam via OfficeKB.com Microsoft Excel Worksheet Functions 13 31st Jul 2005 03:59 PM
"Drop the lowest" in computing average Matthew Leingang Microsoft Excel Worksheet Functions 8 8th Jun 2005 12:31 AM
Incorrect arithmetic when computing Average (hours:minutes) =?Utf-8?B?VGltIGluIE1pY2hpZ2Fu?= Microsoft Excel Worksheet Functions 3 2nd Oct 2004 01:40 PM
eliminating #value when computing average Junior Microsoft Excel Programming 2 25th Jun 2004 12:59 AM
Re: Computing an average that excludes error message Ron de Bruin Microsoft Excel Worksheet Functions 0 23rd Jul 2003 10:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:20 AM.