Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Applications / Excel / March 2005



Tip: Looking for answers? Try searching our database.

Divide by Zero error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Barton - 24 Feb 2005 16:56 GMT
A portion of code inside a form has suddenly started misbehaving in Excel
2004 v 11.1.0. The same code works without problems in Excel X & 2001 and
has worked OK in 2004 before.

* The code is located inside a form.
* Three different integer variables are assigned three different constants
(all integer values).
* The third assignment fails and produces a 10: Divide by zero error.
* On subsequent passes (using Set Next Statement), a 6: Overflow error is
generated.

Can anyone suggest a reason for this?

Many thanks,

Mike Barton
Bob Greenblatt - 24 Feb 2005 20:18 GMT
On 2/24/05 11:56 AM, in article BE43B7BD.2E5B%mbarton@ntlworld.com, "Mike
Barton" <mbarton@ntlworld.com> wrote:

> A portion of code inside a form has suddenly started misbehaving in Excel 2004
> v 11.1.0. The same code works without problems in Excel X & 2001 and has
[quoted text clipped - 12 lines]
>
> Mike Barton

Post the code. Then we can help.

Signature

Bob Greenblatt [MVP], Macintosh
bobgreenblattATmsnDOTcom

Mike Barton - 25 Feb 2005 00:16 GMT
Please find relevant portion of code below. The code breaks on the line
reading ŒintMaxWidth = CONST_MAX_WIDTH_MAC10¹.

> Private Const CONST_MIN_WIDTH_MAC10 As Single = 230
> Private Const CONST_MAX_WIDTH_MAC10 As Single = 582
[quoted text clipped - 53 lines]
>     EBErrorHandler "frmReconciliation-cmbLineCode_Change"
> End Sub

> On 2/24/05 11:56 AM, in article BE43B7BD.2E5B%mbarton@ntlworld.com, "Mike
> Barton" <mbarton@ntlworld.com> wrote:
[quoted text clipped - 17 lines]
>
> Post the code. Then we can help.
Bob Greenblatt - 25 Feb 2005 13:25 GMT
I don¹t see anything wrong. And, it works fine for me, no error is generated
on that line, and intmaxwidth obtains the proper value. Try ³cleaning² the
vba code.

Copy ALL the code to text files. Delete the modules. Remove all the code
from the form pane(s). Save and close the workbook. Then reopen it and paste
the code back, compile and test it again.

Signature

Bob Greenblatt [MVP], Macintosh
bobgreenblattATmsnDOTcom

Fredrik Wahlgren - 25 Feb 2005 21:42 GMT
Re: Divide by Zero error
 I don't see anything wrong. And, it works fine for me, no error is generated on that line, and intmaxwidth obtains the proper value. Try "cleaning" the vba code.

 Copy ALL the code to text files. Delete the modules. Remove all the code from the form pane(s). Save and close the workbook. Then reopen it and paste the code back, compile and test it again.

 --
 Bob Greenblatt [MVP], Macintosh
 bobgreenblattATmsnDOTcom

 I think the file may have become corrupt. That would explain why bob doesn't get any errors. Bob's suggestion may fix the problem. I'm pretty sure there won't be a problem if you create a new file from scratch.

 /Fredrik
Mike Barton - 04 Mar 2005 00:53 GMT
Bob,

I created a new add-in workbook, inserted new modules/form and copied the
code and the form controls to the new version.

I have tried this new file under both Excel X and Excel 2004. It still works
fine under Excel X and still generates the same error under Excel 2004.

If you think the corruption might be in the controls, I will re-enter the
controls rather than copying.

> I don¹t see anything wrong. And, it works fine for me, no error is generated
> on that line, and intmaxwidth obtains the proper value. Try ³cleaning² the vba
[quoted text clipped - 3 lines]
> the form pane(s). Save and close the workbook. Then reopen it and paste the
> code back, compile and test it again.
spacemodler - 25 Mar 2005 17:31 GMT
I was getting a divide by zero error at odd places after I upgraded to
2004 from X.  (Do an assignment, did a comparaions of the variable just
assigned poof divide by zero error, but only while in the debigger.)
It went away after I purged all of my old microsoft preferences.  I
suspect that Excel was referencing the wrong libraries for my VBA code.

I recogized this as a preferences problem, when I experimented with the
same version of excel under different accounts on my machine.  New
accounts didn't have the problem, my regular account did.  Cleaned
preferences problem went away.
JE McGimpsey - 25 Feb 2005 14:28 GMT
> Please find relevant portion of code below. The code breaks on the line
> reading ŒintMaxWidth = CONST_MAX_WIDTH_MAC10¹.

As Bob said, there's nothing wrong with your code at that point. It runs
fine for me using XL04. Perhaps cleaning will help.

Note that your original post said that

>> * Three different integer variables are assigned three different
>> constants (all integer values).

That parenthetical statement's not true, since you've defined your
constants as Single (floating point). That requires an implicit coercion
at assignment. It's probably not related to your problem, but it might
be relevant to the overflow statement (I'm not sure where you set your
Set Next command, so I don't know how you generated a second pass).

I rarely use anything but Long and Double for numeric variables. Using
the shorter forms doesn't save significant amounts of memory (or any, in
the case of integer vs. long), and doesn't require freqent explicit or  
implicit coercions.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.