As stated in an earlier post, I have been using this stair project as a good beginners VBA coding exercise. I had little prior experience with VBA. Thanks to everyone here who helped push me into the right directions. The resulting code came out of it, and I just wanted to share it with everone else. Pass it along to other people who may be just beginning.
Option Explicit
Dim pt As Variant
Public Ab0 As Double
Public Bb0 As Double
Public R As Integer
Public X As Double
Public Y As Double
Dim p As Variant
Dim i As Integer
Dim RR
Dim PLP As Double
Dim rl As Integer
Dim rk As Integer
Dim rj As Integer
Public Sub stair()
pt = ThisDrawing.Utility.GetPoint(, "Select Point") 'gets point from user input.
Ab0 = pt(0) 'assigns the X variant of point.
Bb0 = pt(1) 'assigns the Y variant of point.
StrOpt.Show 'opens form for user input.
End Sub
Public Sub makestair()
R = StrOpt.textboxR 'This is the number of risers from form
X = StrOpt.textboxX 'This is the Run of the riser from form
Y = StrOpt.textboxY 'This is the Rise of the riser from form
RR = (R * 2) + 1 ' This is the number of times the step needs to repeat. 4 Risers will require
'9 points in the polyline, 9 points will require 18 coordinates(x,y).
rl = 2 * RR - 1 'Used to identify the number of coordinates needed.
ReDim PLP(0 To rl) As Double 'PLP - PolyLinePoints - is a variant with a variable range.
Set p = New Collection ' You always have to do this with a collection before you can use it.
For i = 1 To RR Step 1 ' i is equal to integers 1 thru RR,(number of points needed for polyline)
rj = 2 * i - 2 ' Gives the PLP variant a unique number. The X coordinate.
rk = 2 * i - 1 ' Gives the PLP variant a unique number. The Y coordinate.
If i Mod 2 = 0 Then 'if i divided by 2 has a remainder of 0, an even number, then I would
'like for PLP(i) to equal the following formula.
PLP(rj) = Ab0 + X * ((i - 2) / 2): PLP(rk) = Bb0 + Y * (i / 2)
' use the colon seperator to identify the X and Y cooridnate.
p.Add (PLP())
Else 'if i divided by 2 has a remainder not equal to 0, odd number, then I
'would like for PLP(i) to equal the following formula.
PLP(rj) = Ab0 + X * ((i - 1) / 2): PLP(rk) = Bb0 + Y * ((i - 1) / 2)
p.Add (PLP())
End If
Next i
ThisDrawing.ModelSpace.AddLightWeightPolyline (PLP()) 'the lightweight polyline only requires an X
' and Y coordinate.
StrOpt.Hide 'Closes the form and ends the program.
End Sub