Consulting

Results 1 to 6 of 6

Thread: Verification on my defining variable and small piece of code

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    24
    Location

    Verification on my defining variable and small piece of code

    I just need some verification that i defined the variables correctly and that these triginometry functions are correct.

    [vba]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[/vba]

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

  2. #2
    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 ...
    2+2=9 ... (My Arithmetic Is Mental)

  3. #3
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    In addition to not using it, you define XS as Intger - it should be Integer (or Long)
    Did you try compiling this?
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    VBAX Regular
    Joined
    Nov 2007
    Posts
    24
    Location
    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.....
    Last edited by kwik10z; 11-29-2007 at 07:23 AM.

  5. #5
    VBAX Regular
    Joined
    Nov 2007
    Posts
    24
    Location
    Quote Originally Posted by rory
    Did you try compiling this?
    sadly...i dont even know what that means??

  6. #6
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Hit Debug->'Compile VBAProject' on the menu and your code will be checked for syntax errors.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •