Bryco 发表于 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


Matt__W 发表于 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&nbsp<--请注意;“向后”;d 

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

Arthur通过点击ALT+F11,可以在Bricscad中使用VBA编辑器
页: [1]
查看完整版本: 感谢大家在这里帮助这个简单的楼梯代码。