![]() |
|
|
#1 |
|
Death or Mau Mau
Join Date: Apr 2003
Location: the Bungle Bungles
Posts: 2,219
Thanks: 0
Thanked 0 Times in 0 Posts
|
VB6 Controls Collection: How to find the index of a control?
Got a form with a control array called ctlTicketLine.
I want to completely remove an element from this array, but to do this I apparently have to delete the control's index property. Can someone tell me how to do this? I can't seem to get the index of it from the Controls array. thanks. |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Jan 2005
Location: I know sophistication, I've been to ...
Posts: 265
Thanks: 0
Thanked 0 Times in 0 Posts
|
See
doesn't work with design time created controls though
__________________
Kind regards, Chitty |
|
|
|
|
|
#3 | |
|
Death or Mau Mau
Join Date: Apr 2003
Location: the Bungle Bungles
Posts: 2,219
Thanks: 0
Thanked 0 Times in 0 Posts
|
Quote:
(for others, the invisible link is: Google Groups ) Last edited by stillill; 14-11-2005 at 12:38. |
|
|
|
|
|
|
#4 |
|
Making a 1% improvement
Join Date: Sep 2000
Location: Essex, UK
Posts: 5,572
Thanks: 12
Thanked 30 Times in 20 Posts
|
If you remove a control from the middle of the array, your array count will drop by one, but you still have to go through them all* to find out which one. (*the max you've had). You can use the tag property of control index 0 to maintain the highest index count.
You can also create a function to determine if a control exists. Just store the controls name into a temp variable, and wrap error checking around it. If it fails, that control doesn't exist. eg, Code:
Function ffn_doesControlExist(ac_control As Control) As Boolean
On Error GoTo ErrHandler
Dim ls_name As String
ls_name = ac_control.Name
ffn_doesControlExist = True
Exit Function
ErrHandler:
Exit Function
'used for debuggin'
Resume
End Function
Code:
if ffn_doesControlExist(command1(2)) = true then ... I'll knock up a sample app to explain this, if you want... |
|
|
|
|
|
#5 | |
|
Death or Mau Mau
Join Date: Apr 2003
Location: the Bungle Bungles
Posts: 2,219
Thanks: 0
Thanked 0 Times in 0 Posts
|
Quote:
For instance, when I Watch the Me.Controls collection, I can see my 3 elements are Item 111,112 and 113 in the collection (it's a busy form). I can't seem to reference them directly however so I can use the Remove method. |
|
|
|
|
|
|
#6 |
|
Making a 1% improvement
Join Date: Sep 2000
Location: Essex, UK
Posts: 5,572
Thanks: 12
Thanked 30 Times in 20 Posts
|
Hmm. If you've 10 command buttons in an array (command1 in the above example, so command1(0), command1(1), command1(2), etc) you can remove one by simply using unload command1(5). Depends on the rest of your code, I suppose, but thats how I've done it in the past.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|