|
-
Sep 4th, 2001, 12:48 AM
#1
control arrays problem
hello
i am having a problem with control arrays
i am dynamically loading and unloading the controls
but an error occurs when a element which is unloaded is refenced
i want to apply a condition to know that wether a element at this
index exists or not.
can any one help me.
-
Sep 4th, 2001, 01:27 AM
#2
Can you try and just catch the element does not exist error instead?
VB Code:
'assumes a Label1 with Index set to 0
Private Sub Form_Load()
Load Label1(1)
Load Label1(2)
Unload Label1(1)
On Error Resume Next
MsgBox Label1(1).Caption
If Err.Number = 340 Then
MsgBox "element does not exist"
End If
End Sub
-
Sep 4th, 2001, 07:12 AM
#3
PowerPoster
Perhaps you should have a public variable that keeps track of the largest possible element. You can incremenet/decrement at will.
-
Sep 7th, 2001, 12:11 PM
#4
description
the place where i am using this control array is critical and cannot rely on these errorr detection codes so i want to know that when a control is unloaded then whats is the thing that resides at that index please send an immediate answer
-
Sep 7th, 2001, 06:46 PM
#5
PowerPoster
hi
i am sure u could find a way to put error detection in any sub that accesses a nonexistent control but if u dont want to go that way u could use a piggy back variable that records the status of each control eg
VB Code:
Private Sub Command1_Click(index As Integer)
Dim IExist() As Boolean
ReDim IExist(4)
For x = 1 To 4
Load Command1(x) 'Create at runtime
IExist(x) = True 'record as existing
Next
Unload Command1(2) 'unload 2
IExist(2) = False 'Set corresponding var to false
For x = 1 To 4
If IExist(x) Then Debug.Print x
Next
End Sub
-
Sep 9th, 2001, 12:48 PM
#6
Here is a function I just made real quick. It should be what you're looking for. Give it the control array and the index value you want to check for. It returns true if the control is there and false if it's not:
VB Code:
Private Function IsLoaded(CtrlArray, Index As Long) As Boolean
Dim tVar
On Local Error GoTo GotErr
tVar = CtrlArray(Index).Tag
IsLoaded = True
Exit Function
GotErr:
IsLoaded = False
End Function
'Usage
If IsLoaded(Command1, 1) Then
MsgBox Command1(1).Caption
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|