Create Lines

Hey guys, I have a code to create the lines of a c-section frame. the code has worked fine but now some of the points are begining to mess up. When I run through it step by step in vba the points read what they should be and the cross sectional shape is right, however if i let vba run itself the points start to intersect. I'm posting the code to determine the points and then the code to create the lines.....hopefully someone will be able to help.

Sub SketchCSection(ErrorMessage As String, ErrorFlag As Integer, ByRef points() As Double, RootX As Double, RootY As Double, bSection As Double, dSection As Double, tSection As Double, MirrorFlag As Boolean)

    Dim Factor As Double

    ErrorFlag = 0

    ErrorMessage = ""

    If MirrorFlag Then

        Factor = -1

   Else

        Factor = 1

    End If

    points(1, 1) = RootX

    points(1, 2) = RootY

    points(2, 1) = RootX

    points(2, 2) = RootY - dSection

    points(3, 1) = RootX + Factor * bSection

    points(3, 2) = RootY - dSection

    points(4, 1) = RootX + Factor * bSection

    points(4, 2) = RootY - dSection + tSection

    points(5, 1) = RootX + Factor * tSection

    points(5, 2) = RootY - dSection + tSection

    points(6, 1) = RootX + Factor * tSection

    points(6, 2) = RootY - tSection

    points(7, 1) = RootX + Factor * bSection

    points(7, 2) = RootY - tSection

    points(8, 1) = RootX + Factor * bSection

    points(8, 2) = RootY

End Sub

Call SketchCSection(ErrorMessage, ErrorFlag, points, RootX, RootY, bSection, dSection, tSection, False)

    If ErrorFlag = 0 Then

        For i = 1 To 8

            If i < 8 Then

                j = i + 1

            Else

                j = 1

            End If

            Set SkSegment = Doc.SketchManager.CreateLine(points(i, 1), points(i, 2), 0#, points(j, 1), points(j, 2), 0#)

        Next i

   

        If SkSegment Is Nothing Then

            ErrorFlag = 2

        End If

SolidworksApi macros