Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catch control from control array

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,509
US
My VB6 app is being re-written in other way, more XXI century. But this is a process and only parts of VB6 app should be dis-abled before the entire app will be put to sleep.
I would like to have a simple way of making certain controls on the Form not visible. My idea is to have a simple table in the DB where I can list controls that I need to hide, something like:

[pre]
FORM CONTROL
frmForm1 cmdGo
frmForm1 cmdStop
frmForm1 fraPizza
frmComp cmdX
[/pre]
I can easily loop thru all the controls on the Form and when control’s name = data from that table, I can make it Visible = False

The question is – what if I have a set of option buttons in a control array:[tt]
optSelect(0)
optSelect(1)
optSelect(2)
optSelect(3)[/tt]
how can I deal with them if I want to ‘catch’ just [tt]optSelect(2)[/tt] and not the other options?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Erm, surely something like:

optSelect(2).Visible = False

Or is their something deeper in your question that I am missing?

 
Yes, there is something 'deeper' :)

If I just use the Name of the control (from my table in DB, let's say [blue]cmdStop[/blue]) then I can simply do:

Code:
Dim c As Control

For Each c In Me.Controls
    If c.Name = [blue]"cmdStop"[/blue] Then
        c.Visible = False
    End If
Next c
Where the [blue]cmdStop[/blue] will come from the DB.
But that will NOT work with control arrays because all of them have the same name.

I guess I will have to have another column in my table with the Caption of the control from control array...

Code:
Dim c As Control

For Each c In Me.Controls
    If Not IsNUll(rst!Cntr_[blue]Name[/blue].Value) Then
        If c.[blue]Name[/blue] = [blue]rst!Cntr_Name.Value[/blue] Then
            c.Visible = False
        End If
    Else
        If c.[red]Caption[/red] = [red]rst!Cntr_Caption.Value[/red] Then
            c.Visible = False
        End If
    End If
Next c

I may have just answered my own question.... [thumbsup2]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top