Co.Mnstr 发表于 2008-10-10 17:08:18

感谢这里的每一个人帮助我们学习这个简单的楼梯代码。

如前一篇文章所述,我一直在使用这个楼梯项目作为VBA编码练习的良好初学者。我之前对VBA几乎没有经验。感谢这里的每个人帮助我走向正确的方向。由此产生的代码来自它,我只想与其他人分享它。将它传递给其他可能刚刚开始的人。
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 hasa 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

**** Hidden Message *****

Bryco 发表于 2008-10-19 22:23:16

我正在努力理解和学习vba是如何运行的。
使用记事本保存代码,请问应该以什么文件扩展名保存?

Matt__W 发表于 2008-10-20 10:17:41

. txt很好,您通常会直接复制并粘贴到. dvd项目中

Matt__W 发表于 2008-10-20 10:31:34


。dvb<-注意“向后”d

Matt__W 发表于 2008-10-20 11:50:45

Arthur
您可以通过点击ALT+F11
Dan来使用Bricscad中的VBA编辑器
页: [1]
查看完整版本: 感谢这里的每一个人帮助我们学习这个简单的楼梯代码。