Solved

Expression too complex error

Posted on 2010-09-02
15
1,092 Views
Last Modified: 2012-05-10
Hi,

I am working on a routine to plot well dimensioned and well positioned circles on a X-Y chart, in another question.

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26426785.html

In the latest version, the question asker suddenly gets a "Expression too complex" error on the line

xScalar = DeltaX / mPA.InsideWidth

A very simple division of 2 Double variables, all three terms of this expression are double.

The error pops up in an iteration loop, limited by hardcoding to 100 iterations.

As I can't reproduce the error, and as the workarounds for this error seem to bring no help (simplifying the expression is not possible and I added a refresh as suggested in a MS article), I'm lost.

This is wat a Microsoft KB article suggested, but this did not help.

    Application.ScreenUpdating = True
    mCh.Chart.Refresh
    DoEvents


Thanks for your insights
ChartMAgic--version-3-.xls
0
Comment
Question by:calacuccia
  • 8
  • 4
  • 3
15 Comments
 
LVL 3

Expert Comment

by:WiB
ID: 33596283

I would remove xScalar <> yScalar from the while loop, because expression is always true
restricting number of iterations doesn't help you neither (error occurs at first iteration)

during execution
xScalar = DeltaX / mPA.InsideWidth

one of the values(DeltaX) is calculated as a finite number, resulting to buffer overflow (as I saw under debugger)

and I didn't get your error in MS Office 2010



0
 
LVL 3

Expert Comment

by:WiB
ID: 33596325
and in 32-bit system only 6 nested levels supported in VB
0
 
LVL 45

Expert Comment

by:aikimark
ID: 33597742
@WiB

>>only 6 nested levels supported in VB
Please cite a reference for this comment or explain in more detail.
0
 
LVL 3

Expert Comment

by:WiB
ID: 33598691
0
 
LVL 3

Expert Comment

by:WiB
ID: 33598794
apparently explicit casting do the trick:

xScalar = CDbl(DeltaX / mPA.InsideWidth)
0
 
LVL 17

Author Comment

by:calacuccia
ID: 33599173
I'll ask the person with the problem to test it :-)

Between the moment that I posted this question and your first replies, the person actually found a solution by doing this:

 xScalar = DeltaX / Round(mPA.InsideWidth, 20)

But I am still stunned by this simple equation raising the error.

0
 
LVL 45

Expert Comment

by:aikimark
ID: 33599278
@WiB

* The article states and 8 level (max) depth limit, not 6.

* The limit is on expression depth with floating point variables and literals -- how many parenthetical sub-expressions are there.

* This limit does not come into play for looping structures.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Expert Comment

by:WiB
ID: 33599389
that solution by rounding to 20 digits is even more strange to me than equation raising the error,
as Excel representation of double type has only 15 significant figures

I would say it is at least a flow in Excel code

P.S.: as you found workaround before the answer, you may delete the question
0
 
LVL 45

Expert Comment

by:aikimark
ID: 33599407
Rather than delete the question, please accept your comment http:#33599173 as the solution.
0
 
LVL 3

Expert Comment

by:WiB
ID: 33599415
aikimark, OK
but since error description is not correct in this case, don't see the point in further discussion
0
 
LVL 45

Expert Comment

by:aikimark
ID: 33599452
>>...further discussion

My last remark was directed to calacuccia, as the correct disposition for this question.
0
 
LVL 3

Expert Comment

by:WiB
ID: 33599650
:)
I actually was commenting your message about limit of levels of nested floating-point expressions
0
 
LVL 17

Author Comment

by:calacuccia
ID: 33600720
I was going to delete the question until you people started working on it :-)

WIB --> If you document this well, you'll get the points :-)

apparently explicit casting do the trick:

xScalar = CDbl(DeltaX / mPA.InsideWidth)

I would remove xScalar <> yScalar from the while loop, because expression is always true
restricting number of iterations doesn't help you neither (error occurs at first iteration)

Indeed, this condition was a leftover from a first trial, afterwards I added the t > 0.002 condition for better convergence. However, why do you state the error occurs after the first iteration? Have you been able to raise the error?
 
0
 
LVL 3

Accepted Solution

by:
WiB earned 500 total points
ID: 33611071
>Indeed, this condition was a leftover from a first trial, afterwards I added the t > 0.002 condition for better
>convergence. However, why do you state the error occurs after the first iteration? Have you been able
>to raise the error?

yes, I got the error on the machine with MS Office 2007 (both Windows XP & Windows Vista)
variables:
DeltaX = 50
mPA.InsideWidth = 570,040078740157
i = 0
xScalar = -1,#IND


I guess this happened because one of the problems of floating-point computation in a computer is that

"operation can be legal in principle, but the result can be impossible to represent in the specified format, because the exponent is too large or too small to encode in the exponent field. Such an event is called an overflow (exponent too large), underflow (exponent too small) or denormalization (precision loss)."

explicit casting normalizes indefinite result


0
 
LVL 17

Author Closing Comment

by:calacuccia
ID: 33611147
Well, thanks for the addition, let's settle it here :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now