如何快速定位一控件是否在该窗体存在

zhufenghappy 2008-07-09 10:35:11
注意,我说的是快速定位,就是不要用下面语句遍历。(比如针对Command1控件)
For Each Control In vform.Controls
if Control.Name=“Command1” then
'操作
end if
next
...全文
79 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhufenghappy 2008-07-09
  • 打赏
  • 举报
回复
索引问题,二楼以解决,但是代码不直接贴出来不太好,呵呵
zhufenghappy 2008-07-09
  • 打赏
  • 举报
回复
呵呵还能看到阿 ,如果带索引怎么解决呢?
zhufenghappy 2008-07-09
  • 打赏
  • 举报
回复
刚才一楼说的不错,不知道怎么看不到了,关键是如果带索引呢比如Command1(0),就不对了。
下面是他原话:

VB codeDim cmd As CommandButton
On Error Resume Next
Set cmd = Me.Controls("Command1")
On Error GoTo 0
Debug.Print IIf(cmd Is Nothing, "不存在", "存在")

yangao 2008-07-09
  • 打赏
  • 举报
回复
http://www.cnblogs.com/topboy168/archive/2007/07/19/823709.aspx

只想到这种处理方法
不知道有没有更简单的
Tiger_Zhao 2008-07-09
  • 打赏
  • 举报
回复
Dim cmd As CommandButton
On Error Resume Next
Set cmd = Me.Controls("Command1")
On Error GoTo 0
Debug.Print IIf(cmd Is Nothing, "不存在", "存在")

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧