Thread: Overflow Error
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Overflow Error


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