找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 812|回复: 3

[VBA函数]:大家看一下这个程序,为什么不运行?

[复制链接]
发表于 2003-3-12 11:20:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
Sub drawcircularpavers()
    Dim brickcircles() As AcadCircle
    Dim center As Variant, radius As Double
    Dim counter As Integer
    ReDim brickcircles(txtnumberofcircles)
    With ThisDrawing.Utility
        center = .GetPoint(, "click the position for the center")
        radius = .GetDistance(center, "enter the radius")
    End With
    For counter = 0 To txtnumberofcircles - 1
    Set brickcircles(counter) = ThisDrawing.ModelSpace.AddCircle(center, (radius - counter * radius / txtnumberofcircles))
    brickcircles(counter).Color = acRed
    brickcircles(counter).Update
    drawmortar
    Next
End Sub
Sub drawmortar(center As Variant, counter As Integer, radius As Double)
    Dim startpoint(0 To 2) As Double, endpoint(0 To 2) As Double
    Dim theta As Double, stepsize As Double
    Static adjust As Double
    If frmcircleofbricks.optbrickparallel = True Then
        stepsize = 15 * 3.1415 / 180
    Else
        stepsize = 30 * 3.1415 / 180
        If adjust = 0# Then
            adjust = 15 * 3.1415 / 180
        Else
            adjust = 0#
        End If
    End If
    For theta = 0 To 360 * 3.1415 / 180 Step stepsize
    startpoint(0) = (radius - counter * radius / txtnumberofcircles) * Cos(theta + adjust) + center(0)
    startpoint(1) = (radius - counter * radius / txtnumberofcircles) * Sin(theta + adjust) + center(1)
    endpoint(0) = (radius - (counter + 1) * radius / txtnumberofcircles) * Cos(theta + adjust) + center(0)
    endpoint(1) = (radius - (counter + 1) * radius / txtnumberofcircles) * Sin(theta + adjust) + center(1)
    startpoint(2) = 0#: endpoint(2) = 0#
    With ThisDrawing.ModelSpace
        .AddLine startpoint, endpoint
        .Item(ModelSpace.Count - 1).Update
    End With
    Next
End Sub


Private Sub cmdcancel_Click()
    Unload Me
End Sub

Private Sub cmdcreatepavers_Click()
    Unload Me
    drawcircularpavers
End Sub
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 181个

财富等级: 日进斗金

发表于 2003-3-12 13:13:18 | 显示全部楼层
主要的问题是在提示用户获取点时没有先隐藏窗体,其它的在编程中注意一下就可以了。

  1.   [FONT=courier new]
  2. Sub drawcircularpavers()
  3. Dim brickcircles() As AcadCircle
  4. Dim center As Variant, radius As Double
  5. Dim counter As Integer
  6. '这里首先应判断文本框是否有输入,是否是数字。
  7. if txtnumberofcircles="" then exit sub
  8. if not isnumeric(txtnumberofcircles) then exit sub
  9. ReDim brickcircles(txtnumberofcircles)
  10. '这里隐藏窗体
  11. frmcircleofbricks.hide
  12. With ThisDrawing.Utility
  13. center = .GetPoint(, "click the position for the center")
  14. radius = .GetDistance(center, "enter the radius")
  15. End With
  16. For counter = 0 To txtnumberofcircles - 1
  17. Set brickcircles(counter) = ThisDrawing.ModelSpace.AddCircle(center, (radius - counter * radius / txtnumberofcircles))
  18. brickcircles(counter).Color = acRed
  19. brickcircles(counter).Update
  20. '下面的语句在过程中定义了参数,但却没有对其赋值。
  21. drawmortar center, counter, radius
  22. Next
  23. End Sub
  24. Sub drawmortar(center As Variant, counter As Integer, radius As Double)
  25. Dim startpoint(0 To 2) As Double, endpoint(0 To 2) As Double
  26. Dim theta As Double, stepsize As Double
  27. Static adjust As Double
  28. If frmcircleofbricks.optbrickparallel = True Then
  29. stepsize = 15 * 3.1415 / 180
  30. Else
  31. stepsize = 30 * 3.1415 / 180
  32. If adjust = 0# Then
  33. adjust = 15 * 3.1415 / 180
  34. Else
  35. adjust = 0#
  36. End If
  37. End If
  38. For theta = 0 To 360 * 3.1415 / 180 Step stepsize
  39. startpoint(0) = (radius - counter * radius / txtnumberofcircles) * Cos(theta + adjust) + center(0)
  40. startpoint(1) = (radius - counter * radius / txtnumberofcircles) * Sin(theta + adjust) + center(1)
  41. endpoint(0) = (radius - (counter + 1) * radius / txtnumberofcircles) * Cos(theta + adjust) + center(0)
  42. endpoint(1) = (radius - (counter + 1) * radius / txtnumberofcircles) * Sin(theta + adjust) + center(1)
  43. startpoint(2) = 0#: endpoint(2) = 0#
  44. With ThisDrawing.ModelSpace
  45. .AddLine startpoint, endpoint
  46. 'Count前不能再有ModelSpace。
  47. .Item(.Count - 1).Update
  48. End With
  49. Next
  50. End Sub


  51. Private Sub cmdcancel_Click()
  52. Unload Me
  53. End Sub

  54. Private Sub cmdcreatepavers_Click()
  55. 'Unload Me 这里就不对了,还没执行程序就把窗体卸载了,后面的程序当然就不执行了。
  56. drawcircularpavers
  57. End Sub
  58.   [/FONT]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2003-3-12 15:13:02 | 显示全部楼层
我很高兴你能帮忙解决这个问题!我是vba的爱好者,只是现在水平还不行!!很希望向你多学些!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 181个

财富等级: 日进斗金

发表于 2003-3-12 18:45:07 | 显示全部楼层
欢迎常来,每个人总有第一次,总有从不熟悉到熟悉的过程。只要自己掌握了编程的方法和技巧,那么你也可以成为VBA的高手。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2025-9-6 19:19 , Processed in 0.315987 second(s), 38 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表