Overflow Error
I'd check to see if the values in the textboxes are really numeric:
If Me.Controls(ScoreBox(i)).Text < "" Then
if isnumeric(me.controls(Scorebox(i)).text then
varSum = varSum + Me.Controls(ScoreBox(i)).Text
varCount = varCount + 1
end if
End If
It could stop other typos, too.
Bishop wrote:
I think the problem is when all of the textboxes are empty. Your suggestion
works... but only if at least one of the textboxes has a value in it.
"Dave Peterson" wrote:
First, I would never use "as Integer". I'd always use "as Long". Same with "As
Single". I'd use "As Double".
Second, you never posted what was in those 18 textboxes. You could add:
Debug.print "i=" & i & " -- " & Me.Controls(ScoreBox(i)).Text
And copy from the immediate window and then paste into any followup message.
So without knowing what's in those textboxes, I'd suggest:
Dim varSum As Long, varCount As Long
Dim ScoringAve As Double
Dim i As Long
For i = 1 To 18
If Me.Controls(ScoreBox(i)).Text < "" Then
varSum = varSum + Me.Controls(ScoreBox(i)).Text
varCount = varCount + 1
End If
Next
ScoringAve = cdbl(varSum) / cdbl(varCount)
But I didn't test any of it. I'm sure my values wouldn't match what you're
seeing.
Bishop wrote:
I have the following code:
Dim varSum As Integer, varCount As Integer
Dim ScoringAve As Double
Dim i As Integer
For i = 1 To 18
If Me.Controls(ScoreBox(i)).Text < "" Then
varSum = varSum + Me.Controls(ScoreBox(i)).Text
varCount = varCount + 1
End If
Next
ScoringAve = (varSum / varCount)
Why am I getting an Overflow error for ScoringAve?
--
Dave Peterson
--
Dave Peterson
|