Bill_Biggs
Well-known Member
- Joined
- Feb 6, 2007
- Messages
- 1,216
I have the following macro in place which creates an ellipse. There are four angles (indicated) where I have to bypass the Function callouts and enter predetermined values. The problem I am having is when the loop gets to the second angle and the fourth angle, X simply becomes 0 and Y does not change its value. But they do on the first and third angle. Can anyone explain that?
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Ellipse()<br><SPAN style="color:#00007F">Dim</SPAN> Ang <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> a <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, b <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, z <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, X <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, Y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> j, R, S, C, G <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br><br>G = 1<br><br>a = 277 <SPAN style="color:#007F00">'Width</SPAN><br>b = 157 <SPAN style="color:#007F00">'Hieght</SPAN><br><br>R = 337.5 <SPAN style="color:#007F00">'--> Center along X</SPAN><br>S = 275 <SPAN style="color:#007F00">'V Center along Y</SPAN><br><br><SPAN style="color:#00007F">For</SPAN> j = 1 <SPAN style="color:#00007F">To</SPAN> 360<br><br>Ang = j<br><br><SPAN style="color:#00007F">If</SPAN> Ang = 90 <SPAN style="color:#00007F">Then</SPAN><br>X = 0 And Y = S <SPAN style="color:#007F00">'1st Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang = 180 <SPAN style="color:#00007F">Then</SPAN><br>X = R - a And Y = 0 <SPAN style="color:#007F00">'2nd Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang = 270 <SPAN style="color:#00007F">Then</SPAN><br>X = 0 And Y = -S <SPAN style="color:#007F00">'3rd Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang = 360 <SPAN style="color:#00007F">Then</SPAN><br>X = R + a And Y = 0 <SPAN style="color:#007F00">'4th Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <br>X = MyFunc(a, b, Ang)<br>Y = MyY(X, Ang)<br><br><SPAN style="color:#00007F">If</SPAN> Ang >= 90 And Ang <= 179 <SPAN style="color:#00007F">Then</SPAN><br>X = X * -1<br>Y = Y * -1<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang >= 180 And Ang <= 269 <SPAN style="color:#00007F">Then</SPAN><br>X = X * -1<br>Y = Y * -1<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang >= 270 And Ang <= 360 <SPAN style="color:#00007F">Then</SPAN><br>X = X * 1<br>Y = Y * 1<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br>Alpha:<br> ActiveSheet.Shapes.AddShape(msoShapeOval, R + X, S - Y, 2, 2).Select<br><br><SPAN style="color:#00007F">Next</SPAN> j<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
And if anyone can suggest a way around the small bit of spaghetti code included, I am all ears. biggrin
<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Ellipse()<br><SPAN style="color:#00007F">Dim</SPAN> Ang <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> a <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, b <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, z <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, X <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN>, Y <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Double</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> j, R, S, C, G <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN><br><br>G = 1<br><br>a = 277 <SPAN style="color:#007F00">'Width</SPAN><br>b = 157 <SPAN style="color:#007F00">'Hieght</SPAN><br><br>R = 337.5 <SPAN style="color:#007F00">'--> Center along X</SPAN><br>S = 275 <SPAN style="color:#007F00">'V Center along Y</SPAN><br><br><SPAN style="color:#00007F">For</SPAN> j = 1 <SPAN style="color:#00007F">To</SPAN> 360<br><br>Ang = j<br><br><SPAN style="color:#00007F">If</SPAN> Ang = 90 <SPAN style="color:#00007F">Then</SPAN><br>X = 0 And Y = S <SPAN style="color:#007F00">'1st Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang = 180 <SPAN style="color:#00007F">Then</SPAN><br>X = R - a And Y = 0 <SPAN style="color:#007F00">'2nd Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang = 270 <SPAN style="color:#00007F">Then</SPAN><br>X = 0 And Y = -S <SPAN style="color:#007F00">'3rd Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang = 360 <SPAN style="color:#00007F">Then</SPAN><br>X = R + a And Y = 0 <SPAN style="color:#007F00">'4th Angle</SPAN><br><SPAN style="color:#00007F">GoTo</SPAN> Alpha<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <br>X = MyFunc(a, b, Ang)<br>Y = MyY(X, Ang)<br><br><SPAN style="color:#00007F">If</SPAN> Ang >= 90 And Ang <= 179 <SPAN style="color:#00007F">Then</SPAN><br>X = X * -1<br>Y = Y * -1<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang >= 180 And Ang <= 269 <SPAN style="color:#00007F">Then</SPAN><br>X = X * -1<br>Y = Y * -1<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">If</SPAN> Ang >= 270 And Ang <= 360 <SPAN style="color:#00007F">Then</SPAN><br>X = X * 1<br>Y = Y * 1<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br>Alpha:<br> ActiveSheet.Shapes.AddShape(msoShapeOval, R + X, S - Y, 2, 2).Select<br><br><SPAN style="color:#00007F">Next</SPAN> j<br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
And if anyone can suggest a way around the small bit of spaghetti code included, I am all ears. biggrin