Home |
Search |
Today's Posts |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
overflow error | Excel Programming | |||
Overflow error.. why? | Excel Discussion (Misc queries) | |||
Overflow error, need help | Excel Programming | |||
Overflow error | Excel Programming | |||
overflow error | Excel Programming |