Do While Variations

Philosophaie

Active Member
Joined
Mar 5, 2010
Messages
256
Invalid procedure call or argument

I have heard that much during the past week.

Here is my code:
Code:
    Pi = Application.WorksheetFunction.Pi
    MA = Cells(4, 3)
    e = Cells(4, 4)
    EA = 100
    diff = 0.02
    Do While (diff > 0.00001 Or diff < -0.00001)
        diff = (EA - 180 / Pi * e * Math.Sin(EA * Pi / 180) - MA) / (180 / Pi * (1 - e * Math.Cos(EA * Pi / 180)))
        EA = EA + diff
    Loop
    EA = EA - 360 * Int(EA / 360)

To not here the infernal "Invalid procedure call or argument" I can set the "Do While" to do:
Code:
Do While diff>0.0001 or
 Do While diff<0.0001
but that is not what the equation says. diff must be but all give the error above:
Code:
 Do While (diff>0.0001 or diff<-0.0001)  or
 Do While Math.Abs(diff)>0.0001   or
 Do While Math.Sqr((diff)^(2))>0.0001

Please can someone show me where I am going wrong.
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
What are the values of MA and e when you get the error?
 
Upvote 0
It's hard to tell because you don't tell us what's in cells C4 and D4, but I suspect you're getting a division by zero. Check your formula.
 
Upvote 0
Not a division by zero, but the same type of thing. Your value of EA grows very large, -5*10^20, which is too big for the sin and cos functions. By the looks of your code, you're expecting some function to converge and are using diff to decide when the value is close enough. Instead it's diverging. diff is increasing monotonically. You'll need to examine your basic logic. I looked at the code and couldn't figure out what exactly you're trying to do.
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,709
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top