vb控件解决方法
vb控件
vb的控件数组中如何判断一个控件元素是否已经加载,如果已经加载,索引值加1,如果未加载就加载此元素?
------解决方案--------------------
------解决方案--------------------
Form中添加一个textBox,Index属性设置为0,然后拷贝入下面代码
Private Sub Command1_Click()
MsgBox CStr(IsLoaded(Text1(0))) &" " & CStr(IsLoaded(Text1(3)))
End Sub
Private Function IsLoaded(obj As Object) As Boolean
On Error GoTo ErrX
Dim i As Long
i = obj.Index
IsLoaded = True
ErrX:
End Function
------解决方案--------------------
用数组添加的时候方便,删除就不方便了.
用集合如何?
vb的控件数组中如何判断一个控件元素是否已经加载,如果已经加载,索引值加1,如果未加载就加载此元素?
------解决方案--------------------
Private Type clsType
cName As String
ID As Integer
End Type
Private Sub Command1_Click()
Dim iCtl As Control, iCls() As clsType
Dim i As Integer
ReDim iCls(0)
For Each iCtl In Controls
iCls(0).cName = TypeName(iCtl) '取得CTRL名称
For i = 1 To UBound(iCls)
If iCls(i).cName = iCls(0).cName Then
iCls(i).ID = iCls(i).ID + 1 '加入CTRL数量
Exit For 'i
End If
Next 'i
If i > UBound(iCls) Then '未寻获
ReDim Preserve iCls(UBound(iCls) + 1) '加入CTRL
iCls(UBound(iCls)).cName = iCls(0).cName '新增名称
iCls(UBound(iCls)).ID = 1 '加入数量
End If
Next 'iCls
For i = 1 To UBound(iCls)
If iCls(i).cName = "TextBox" Then Exit For '寻获CTRL,离开i
Next 'i
If i > UBound(iCls) Then '未寻获
Set iCtl = Controls.Add("VB.TextBox", "Text1", Me)
' 其它对该物件位移、植入资料...等,就自己加罗
iCtl.Visible = True '最後才显示出来
End If
End Sub
------解决方案--------------------
Form中添加一个textBox,Index属性设置为0,然后拷贝入下面代码
Private Sub Command1_Click()
MsgBox CStr(IsLoaded(Text1(0))) &" " & CStr(IsLoaded(Text1(3)))
End Sub
Private Function IsLoaded(obj As Object) As Boolean
On Error GoTo ErrX
Dim i As Long
i = obj.Index
IsLoaded = True
ErrX:
End Function
------解决方案--------------------
用数组添加的时候方便,删除就不方便了.
用集合如何?