LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Overflow Error


And adding Keiji's response:

if varcount = 0 then
'what should happen to scoringave
else
ScoringAve = varSum) / varCount
end if

I would keep the tests for numbers, too.

Dave Peterson wrote:

In fact...

If Me.Controls(ScoreBox(i)).Text < "" Then
if isnumeric(me.controls(Scorebox(i)).text then
varSum = varSum + cdbl(Me.Controls(ScoreBox(i)).Text)
varCount = varCount + 1
end if
End If

Dave Peterson wrote:

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


--

Dave Peterson


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
overflow error Brad Excel Programming 4 April 2nd 09 10:39 PM
Overflow error.. why? Fingerjob Excel Discussion (Misc queries) 4 November 13th 06 05:18 PM
Overflow error, need help mkerstei[_15_] Excel Programming 3 July 14th 06 03:10 AM
Overflow error Grd Excel Programming 1 January 21st 06 08:13 AM
overflow error ExcelMonkey[_5_] Excel Programming 6 January 22nd 04 02:34 AM


All times are GMT +1. The time now is 05:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"