乐筑天下

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

[编程交流] VBA - Using IF and selection s

[复制链接]

21

主题

146

帖子

127

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
106
发表于 2022-7-6 17:15:59 | 显示全部楼层 |阅读模式
I decided that I wanted to understand how to use 'If Then Else' statements, so my first task was to scan the drawing for circles and then have a statement on the command prompt that lets me know whether there are or arent.
 
Above, in the code, you can see I have made a selection set that selects all the objects in a drawing. I then want to ask if there are any circles present in that selection set and then insert two lines of code which will be the answer to my question.
 
Can anyone advise, please?
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 17:34:29 | 显示全部楼层
If sset1Obj.Count  0 Then
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 17:55:09 | 显示全部楼层
Something like this:
 
  1. Sub ScanForCircles()Dim sCol As AcadSelectionSetsDim sset1Obj As AcadSelectionSetDim fTyp(0 To 0) As IntegerDim fDat(0 To 0) As VariantSet sCol = ThisDrawing.SelectionSetsOn Error Resume NextsCol.Item("SSET1").DeleteSet sset1Obj = sCol.Add("SSET1")fTyp(0) = 0fDat(0) = "CIRCLE"sset1Obj.Select acSelectionSetAll, , , fTyp, fDatMsgBox "There is " & sset1Obj.Count & " circles."sset1Obj.DeleteSet sset1Obj = NothingEnd Sub
回复

使用道具 举报

21

主题

146

帖子

127

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
106
发表于 2022-7-6 18:06:07 | 显示全部楼层
 
 
That's great again, thanks.
 
Just a quick question, mate:
 
I Understand what the 'MsgBox' represents but I don't fully understand what the quote marks represent. Obviously the ones at either end are essential, but the ones in-between the text I am unsure exactly how they work in VBA along with the '&' aswell.
 
Can you explain, please?
回复

使用道具 举报

0

主题

132

帖子

198

银币

限制会员

铜币
-21
发表于 2022-7-6 18:29:43 | 显示全部楼层
I can try and explain. A message box feeds a string to the screen via a dialog box. What is shown is a concatenation (joining) of a string. It shows a string, denoted by "There is " and then it is joining (&) it to a string value (actually a integer that VB converts to a string) sset1Obj.Count and then joining (&) another string to that " circles." WHat you end up with is a message box that shows "There is 2 circles" when the selection set has two items in it.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 16:23 , Processed in 0.388674 second(s), 62 queries .

© 2020-2025 乐筑天下

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