对一个Frame内控件的遍历

1 .
Dim  objControl  As  Control

For   Each  objControl  In   Me .Controls
If  objControl.Container.Name  =   " Frame1 "   Then
Debug.Print objControl.Name
End   If
Next


2 .
Public   Sub  OperateFrame( ByRef  objFrame  As  VB.Frame,  ByVal  intOperation  As   Integer )
' \\***********************************************************************
'
\\函 数 名:OperateFrameTextBox
'
\\输 入: ByRef objFrame(VB.Frame) -
'
\\ : ByVal intOperation(Integer)
'
\\ 1: 表示清空TextBox,
'
\\ 2: 表示Enable所有TextBox
'
\\输 出:无
'
\\功能描述:对一个Frame内的TextBox或者ComboBox进行操作,如清空TextBox,Enable或者Disable等
'
\\全局变量:
'
\\使用例子:Call OperateFrame(Me.Frame2, 3)
'
\\日 期:2004-09-22
'
\\修 改 人:
'
\\日 期:
'
\\版 本:V1.0.0
'
*************************************************************************
Dim  objControl  As  Control
Dim  TopForm  As  VB.Form

On   Error   GoTo  ErrHandle

Set  TopForm  =  GetTopContainer(objFrame)

For   Each  objControl  In  TopForm.Controls
Select   Case  intOperation
Case   1
' \\ 1 表示清空frame内所有TextBox
If  (objControl.Container.Name  =  objFrame.Name)  And  ( TypeName (objControl)  =   " TextBox " Then
objControl.Text 
=   ""
End   If
Case   2
' \\ 2 表示Enable所有frame内的TextBox
If  (objControl.Container.Name  =  objFrame.Name)  And  ( TypeName (objControl)  =   " TextBox " Then
objControl.Enabled 
=   True
End   If
Case   3
' \\ 2 表示Enable所有frame内的TextBox
If  (objControl.Container.Name  =  objFrame.Name)  And  ( TypeName (objControl)  =   " TextBox " Then
objControl.Enabled 
=   False
End   If

Case   Else

End   Select
Next

ErrHandle:
If  Err.Number  <>   0   Then
MsgBox  Err.Description, vbCritical,  " 提示 "
Err.Clear
End   If

End Sub

Public   Function  GetTopContainer( ByRef  objCtl  As  Control)  As   Object
' \\***********************************************************************
'
\\函 数 名:GetTopContainer
'
\\输 入:ByRef objCtl(Object)
'
\\输 出:(Object)
'
\\功能描述:获得某控件的顶层容器
'
\\使用例子:Set TopForm = GetTopContainer(objFrame)
'
\\全局变量:
'
\\日 期:2004-09-22
'
\\修 改 人:
'
\\日 期:
'
\\版 本:V1.0.0
'
*************************************************************************
Dim  objContainer  As   Object
Dim  objMe  As   Object
Dim  i  As   Integer
=   1

On   Error   GoTo  ErrHandle

' \\一层层向上获得Container,直到最高一层(为Form对象)
'
\\这时候由于不存在Container对象,会诱发错误438(对象不支持该属性或方法)
Set  objMe  =  objCtl
Do   Until   1   =   2
If  i  >   2   Then
Set  objMe  =  objContainer
End   If
Set  objContainer  =  objMe.Container
=  i  +   1
If  i  >   100   Then
' \\当循环超过100次,应该是存在错误了
MsgBox   " 异常情况!! " , vbCritical,  " 提示 "
Exit Function
End   If
DoEvents
Loop

ErrHandle:
If  Err.Number  <>   0   Then
If  Err.Number  =   438   Then
Set  GetTopContainer  =  objMe
Else
MsgBox  Err.Description, vbCritical,  " 提示 "
End   If
End   If

End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值