PDA

View Full Version : Verification on my defining variable and small piece of code



kwik10z
11-29-2007, 05:09 AM
I just need some verification that i defined the variables correctly and that these triginometry functions are correct.

Sub Insert_TrigFunctions()
Dim XC As Integer, YC As Integer
' XC, YC are coordinates of center of IC chip
Dim XP As Integer, YP As Integer
' XP, YP are coordinates of center of pad relative to chip
Dim Rot As Double, DV As Double
' Rot is Rotation angle, DV is a vector -- distance between center of chip to center of pad
Dim XS As Intger, YS As Integer
' XS, YS are XY coordinates of solder dot
Dim THETA As Integer
' THETA is the angle of pad relative to center of chip

Set DV = Sqrt(XP ^ 2 + YP ^ 2)
' Equation to find the Vector
Set THETA = Degrees(ATAN(YP / XP))
' Equation to find THETA angle
Set YS = DV * Sin(Radians(THETA))
' Equation to give YS in radians rather than degrees

If XP < 0 Then
THETA = THETA + 180 ' If XP is less than 0, rotate the chip 180degrees
End If
End Sub

Thanks....the THETA is that if the angle is less than 0, rotate 180 degrees.

unmarkedhelicopter
11-29-2007, 06:07 AM
A few points :-
1. You mean trigonometric functions ?
2. You shouldn't use integers anymore, longs are better and faster.
3. You define Rot as double but THETA as integer ?
4. DV is not a vector, it is a distance.
5. SQRT() is a worksheet function not a VBA function, use DV = (XP^2+YP^2)^0.5 instead
6. ATAN() is a worsheet function not a VBA function, use ATn() instead
7. ATn() will return radians, multiply by 180/pi to get degrees. Degrees is a worksheet function
8. Radians is a worksheet function, multiply by pi/180 instead
9. What are all the "Set"'s for ?
10. YS = DV * Sin(Radians(THETA)) you have not given any information about the solder dot which says this is true
11. What about XS ? why bother define it if you're not going to use it ?
You have not passed any values to the initial variables, so for example XP = 0, YP = 0 and thus DV = 0. You should either hard code them into your code or pass them as parameters.

Other than that it seems fine ...

rory
11-29-2007, 06:27 AM
In addition to not using it, you define XS as Intger - it should be Integer (or Long)
Did you try compiling this?

kwik10z
11-29-2007, 07:07 AM
On your notes....numbers 7 and 8....could you write the lil equation where the pi/180 goes exactly? please and thank you!

thanks alot for the notes...sorry for all the confusion...i have no programming experience/knowledge....and my boss is pressuring me to do this.....
and to answer your "what about XS?"

im going to use it eventually..just havent gotten that far in the code...haha....sorry!! i hate this stuff.....:(

kwik10z
11-29-2007, 07:33 AM
Did you try compiling this?

sadly...i dont even know what that means?? :dunno

rory
11-29-2007, 07:45 AM
Hit Debug->'Compile VBAProject' on the menu and your code will be checked for syntax errors.