乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 74|回复: 4

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

[复制链接]

7

主题

16

帖子

2

银币

初来乍到

Rank: 1

铜币
44
发表于 2008-10-10 17:08:18 | 显示全部楼层 |阅读模式
如前一篇文章所述,我一直在使用这个楼梯项目作为VBA编码练习的良好初学者。我之前对VBA几乎没有经验。感谢这里的每个人帮助我走向正确的方向。由此产生的代码来自它,我只想与其他人分享它。将它传递给其他可能刚刚开始的人。
  1. Option Explicit
  2. Dim pt As Variant
  3. Public Ab0 As Double
  4. Public Bb0 As Double
  5. Public R As Integer
  6. Public X As Double
  7. Public Y As Double
  8. Dim p As Variant
  9. Dim i As Integer
  10. Dim RR
  11. Dim PLP As Double
  12. Dim rl As Integer
  13. Dim rk As Integer
  14. Dim rj As Integer
  15. Public Sub stair()
  16. pt = ThisDrawing.Utility.GetPoint(, "Select Point") 'gets point from user input.
  17. Ab0 = pt(0)                                         'assigns the X variant of point.
  18. Bb0 = pt(1)                                         'assigns the Y variant of point.
  19. StrOpt.Show                                         'opens form for user input.
  20. End Sub
  21. Public Sub makestair()
  22. R = StrOpt.textboxR 'This is the number of risers from form
  23. X = StrOpt.textboxX 'This is the Run of the riser from form
  24. Y = StrOpt.textboxY 'This is the Rise of the riser from form
  25. RR = (R * 2) + 1    ' This is the number of times the step needs to repeat. 4 Risers will require
  26.                     '9 points in the polyline, 9 points will require 18 coordinates(x,y).
  27. rl = 2 * RR - 1     'Used to identify the number of coordinates needed.
  28. ReDim PLP(0 To rl) As Double    'PLP - PolyLinePoints - is a variant with a variable range.
  29.     Set p = New Collection      ' You always have to do this with a collection before you can use it.
  30.     For i = 1 To RR Step 1      ' i is equal to integers 1 thru RR,(number of points needed for polyline)
  31.         rj = 2 * i - 2          ' Gives the PLP variant a unique number. The X coordinate.
  32.         rk = 2 * i - 1          ' Gives the PLP variant a unique number. The Y coordinate.
  33.         
  34.         If i Mod 2 = 0 Then     'if i divided by 2 has a remainder of 0, an even number, then I would
  35.                                 'like for PLP(i) to equal the following formula.
  36.                        
  37.             PLP(rj) = Ab0 + X * ((i - 2) / 2): PLP(rk) = Bb0 + Y * (i / 2)
  38.                                 ' use the colon seperator to identify the X and Y cooridnate.
  39.             p.Add (PLP())
  40.             
  41.         Else                    'if i divided by 2 has  a remainder not equal to 0, odd number, then I
  42.                                'would like for PLP(i) to equal the following formula.
  43.                         
  44.             PLP(rj) = Ab0 + X * ((i - 1) / 2): PLP(rk) = Bb0 + Y * ((i - 1) / 2)
  45.             p.Add (PLP())
  46.         End If
  47.     Next i
  48.                                 
  49. ThisDrawing.ModelSpace.AddLightWeightPolyline (PLP())   'the lightweight polyline only requires an X
  50.                                                         ' and Y coordinate.
  51. StrOpt.Hide                                             'Closes the form and ends the program.
  52. End Sub

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2008-10-19 22:23:16 | 显示全部楼层
我正在努力理解和学习vba是如何运行的。
使用记事本保存代码,请问应该以什么文件扩展名保存?
回复

使用道具 举报

86

主题

744

帖子

6

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1092
发表于 2008-10-20 10:17:41 | 显示全部楼层
. txt很好,您通常会直接复制并粘贴到. dvd项目中
回复

使用道具 举报

86

主题

744

帖子

6

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1092
发表于 2008-10-20 10:31:34 | 显示全部楼层

。dvb<-注意“向后”d
回复

使用道具 举报

86

主题

744

帖子

6

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1092
发表于 2008-10-20 11:50:45 | 显示全部楼层
Arthur
您可以通过点击ALT+F11
Dan来使用Bricscad中的VBA编辑器
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-4 01:10 , Processed in 1.326546 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表