Author Topic: Thanks to everyone here in helping with this simple stair code.  (Read 2294 times)

0 Members and 1 Guest are viewing this topic.

Co.Mnstr

  • Guest
Thanks to everyone here in helping with this simple stair code.
« on: October 10, 2008, 05:08:18 PM »
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.

Code: [Select]
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

Arthur Gan

  • Guest
Re: Thanks to everyone here in helping with this simple stair code.
« Reply #1 on: October 19, 2008, 10:23:16 PM »
i'm trying to understand and learn how vba runs.
using notepad to dave the code, may i ask what file extension it should saved in?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Thanks to everyone here in helping with this simple stair code.
« Reply #2 on: October 20, 2008, 10:17:41 AM »
.txt is fine, you normally copy and paste directly into a .dvd project

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Thanks to everyone here in helping with this simple stair code.
« Reply #3 on: October 20, 2008, 10:31:34 AM »
.txt is fine, you normally copy and paste directly into a .dvd project

.dvb   <-- Note the "backwards" d   :wink:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8698
  • AKA Daniel
Re: Thanks to everyone here in helping with this simple stair code.
« Reply #4 on: October 20, 2008, 11:50:45 AM »
Arthur

You can use the VBA Editor in Bricscad by hitting ALT + F11
Dan