The DVD Forums


Registered users see fewer advertisements


Go Back   The DVD Forums > Gadgets and Gizmos > Computing Forum

Reply
 
Thread Tools Display Modes
Old 14-11-2005, 11:37   #1
stillill
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.
stillill is offline   Reply With Quote
Old 14-11-2005, 12:30   #2
chitty
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
chitty is offline   Reply With Quote
Old 14-11-2005, 12:34   #3
stillill
Death or Mau Mau
 
Join Date: Apr 2003
Location: the Bungle Bungles
Posts: 2,219
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by chitty
See

doesn't work with design time created controls though
Thanks, I'll have a look. It's a design-time created array though. Seems like a reasonable thing to do, but later my code is looking for an element I've unloaded. Will keep digging.

(for others, the invisible link is:
Google Groups
)

Last edited by stillill; 14-11-2005 at 12:38.
stillill is offline   Reply With Quote
Old 14-11-2005, 13:30   #4
Chris Locke
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
So, you can check if command1(2) exists by using:
Code:
if ffn_doesControlExist(command1(2)) = true then ...
etc.

I'll knock up a sample app to explain this, if you want...
Chris Locke is offline   Reply With Quote
Old 14-11-2005, 15:34   #5
stillill
Death or Mau Mau
 
Join Date: Apr 2003
Location: the Bungle Bungles
Posts: 2,219
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Chris Locke
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
So, you can check if command1(2) exists by using:
Code:
if ffn_doesControlExist(command1(2)) = true then ...
etc.

I'll knock up a sample app to explain this, if you want...
Thanks for the effort Chris, I appreciate it. Seems a bit longwinded to have to check if the control exists right enough. I thought I'd be able to use the Me.Controls.Remove method to remove one element of a control array.

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.
stillill is offline   Reply With Quote


Old 14-11-2005, 16:24   #6
Chris Locke
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.
Chris Locke is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:29.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2008 Poisonous Monkey Ltd