如果要判断一个按钮是否存在怎么写?

李赞红 2003-11-10 12:40:20
如果要判断一个按钮是否存在怎么写?这个按钮是动态生成的.
...全文
126 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcc 2003-11-11
  • 打赏
  • 举报
回复
sorry!
boydgmx(梦霄)兄弟说的对!

还是遍历比较可靠
planetike 2003-11-11
  • 打赏
  • 举报
回复
Dim ctl As Control
For Each ctl In Me.Controls
If (TypeOf ctl Is CommandButton) And (ctl.Name = "Command1") Then
MsgBox "按钮Command1存在"
End If
Next
正解
lxcc 2003-11-10
  • 打赏
  • 举报
回复
Private Sub Command2_Click()
If TypeName(Me.Controls("command1")) = "CommandButton" Then
MsgBox "存在"
End If
End Sub
射天狼 2003-11-10
  • 打赏
  • 举报
回复
Dim ctl As Control

For Each ctl In Controls
MsgBox ctl.Name
Next
z_yanjie 2003-11-10
  • 打赏
  • 举报
回复
Dim ctl As Control
For Each ctl In Me.Controls
If (TypeOf ctl Is CommandButton) And (ctl.Name = "Command1") Then
MsgBox "按钮Command1存在"
End If
Next
boydgmx 2003-11-10
  • 打赏
  • 举报
回复
lxcc(虫莲)
Private Sub Command2_Click()
If TypeName(Me.Controls("command1")) = "CommandButton" Then
MsgBox "存在"
End If
End Sub
------------------------
这种写法如果不存在,则会保错!!还不如遍历之。
boydgmx 2003-11-10
  • 打赏
  • 举报
回复
不好意思,写错了,使用For Each的使用不能再用Count属性,正确如下:
Dim ctl As Control
For Each ctl In Me.Controls
If (TypeOf ctl Is CommandButton) And (ctl.Name = "Command1") Then
MsgBox "按钮Command1存在"
End If
Next
boydgmx 2003-11-10
  • 打赏
  • 举报
回复
Dim ctl As Control
For Each ctl In Me.Controls.Count
If (TypeOf ctl Is CommandButton) And (ctl.Name = "Command1") Then
MsgBox "按钮Command1存在"
End If
Next
kimurakenshin 2003-11-10
  • 打赏
  • 举报
回复
学习……
cfan246 2003-11-10
  • 打赏
  • 举报
回复
learned
conghui 2003-11-10
  • 打赏
  • 举报
回复
dim i as integer
For i = 0 To Me.Count - 1
If TypeOf Me.Controls(i) Is CommandButton Then
MsgBox "存在"
End If
Next i

7,789

社区成员

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

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