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!

Control Array Vuible property not being set

Status
Not open for further replies.

jgo333n

Programmer
Jul 16, 2007
27
GB
Windows Vista VB6 SP6

I have a control array where all properties are being set except for Visible I try to set it. When the line executes it setps over and appears to execute successfully, the line below (Enabled) behaves the save except that the Enabled value is set and the Visible property remains set at False.

Has anyone experienced this before and if so di you manage to resolve it and how?

If Len(Trim(cntrol.Caption)) > 0 Then
With frm.picSG15But(intCounter)
intButtonCounter = intButtonCounter + 1
.Visible = True
.Enabled = True
.Tag = cntrol.Tag & ";Visible"
End With

With frm.SG15Blbl(intCounter)
Set .Container = frm.picSG15But(intCounter)
.Caption = Trim(cntrol.Caption)
.Visible = True
.Tag = cntrol.Tag & ";Visible"
End With

End If
 
Do you have [tt]Option Explicit[/tt] on the top of your code?
How is your [tt]control[/tt] defined? As Control?

(Please use code Tags to show your code)


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 


Option explicit is turned on and the control as declared as a control.


in fact I say


dim control as control

for each control in Me.controls
.
.
If Len(Trim(cntrol.Caption)) > 0 Then
With frm.picSG15But(intCounter)
intButtonCounter = intButtonCounter + 1
.Visible = True
.Enabled = True
.Tag = cntrol.Tag & ";Visible"
End With

With frm.SG15Blbl(intCounter)
Set .Container = frm.picSG15But(intCounter)
.Caption = Trim(cntrol.Caption)
.Visible = True
.Tag = cntrol.Tag & ";Visible"
End With

End If
.
.
next
 
(Please use code Tags to show your code) - again

Also, please do not TYPE your code in here, copy and paste it.
[tt]cntrol[/tt] is not declared here, your 'Run with Full Compile' should not work.
[tt]control[/tt] is very bad name for a variable, it is a reserved word in VB

You do Loop thru all Controls on your Form, but what do you actually want to do with them in the loop once you find them? Do you want all Picture Boxes/Labels to be visible, enabled, and have a Tag ";Visible"?

Code:
Dim control As control

For Each control In Me.Controls

If Len(Trim([red]cntrol[/red].Caption)) > 0 Then
    With frm.picSG15But(intCounter)
        intButtonCounter = intButtonCounter + 1
        .Visible = True
        .Enabled = True
        .Tag = cntrol.Tag & ";Visible"
    End With
    
    With frm.SG15Blbl(intCounter)
        Set .Container = frm.picSG15But(intCounter)
        .Caption = Trim(cntrol.Caption)
        .Visible = True
        .Tag = cntrol.Tag & ";Visible"
    End With

End If

Next

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
One possibility: if the control's parent is not Visible, then you cannot set the control's Visible property to true (actually not entirely accurate, but good enough for now)
 
sorry it should have read:

Dim cntrol As control

For Each cntrol In Me.Controls

And yes I did copy and paste not type , as I am not that dim.
 
We can go around and around with me asking you to answer all of my questions, but the gist of the idea of looping thru all Controls on the Form and doing something to them is:

Code:
Dim cntr As Control

For Each cntr In Me.Controls[blue]
    If TypeOf cntr Is Label Then[/blue]
        With cntr
            .Visible = True
            .Enabled = True
            .Tag = .Tag & ";Visible"
        End With[blue]
    End If[/blue]
Next

This code will loop thru all controls on the Form, and only for [blue]Labels[/blue] on the Form - it will make them visible, enabled, and add to its Tag words ‘;Visible’

This code will not ‘touch’ any other controls, i.e. buttons, pictures boxes, etc. Just labels.

And as strongm said, if control’s Container is not visible, the controls in that Container will not be visible. Also, if Container’s Enabled property is set to False, none of the Controls in that Container can receive click or other events because Container is dis-abled

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
>the controls in that Container will not be visible

It's more than that. They will exhibit the exact behaviour described by the OP:

"When the line executes it ... appears to execute successfully, ... except that ... the Visible property remains set at False."
 
Here is the complete method, the container for these control arrays is DEFINITLY Visible. When we iterate the SG15Blbl is contained inside the picSG15But. and when we set the .Visible property of the SG15Blbl is DOES get set to True, even though its container picSG15But is set to false. As to why the Visible property is not being set but simply appearing to be executed successfully is a mystery. I have spent too much time on this and whilst the code looks correct and executes with out error in a manner I expect it to it does nto hsow the picSG15But elecment. to this ends I have now implemented another method, by examining the Tag for the word visible and set the control property to Visible = True in a separate sub routine. This works as I expect it to.

Why ? I do not know.


intRowCounter = 0
For Each cntrol In frm.Controls
If TypeOf cntrol Is SSCommand Then
If intCounter > 0 Then
'LOAD A NEW ELEMENT INTO THE ARRAY
Load frm.SG15Blbl(intCounter)
Load frm.picSG15But(intCounter)
End If

If Len(Trim(cntrol.Caption)) > 0 And InStr(UCase(cntrol.Caption), "SSCOM") = 0 Then
With frm.picSG15But(intCounter)
intButtonCounter = intButtonCounter + 1
.Visible = True
'this line above fails
.Enabled = True
.Tag = cntrol.Tag & ";Visible"
End With

With frm.SG15Blbl(intCounter)
Set .Container = frm.picSG15But(intCounter)
.Caption = Trim(cntrol.Caption)
.Visible = True this line works
.Tag = cntrol.Tag & ";Visible"
End With

End If
'INCREMENT COUNTER
intCounter = intCounter + 1
End If
' Debug.Print "'" & frm.SG15Blbl(intCounter).Tag & "'"
Next
 
Can't say what is happening, then. On my dev box I can only replicate[sup]1[/sup] the reported behaviour if the container for picSG15But is not visible. If it is, then the code works exactly as expected.

[sup]1[/sup]And even that's only temporary - the moment the container is set visible the it cascades to the contained control, whose .visible property then also switches to .visible
 
I have achieved the behaviour I require by using a different approach.

Thank you every body for your help.

I never got the issue resolved.
 
(Please use code Tags to show your code) - again, and again and again :-(

Is it possible you set your labels’ Visible to True while your picture box’s Visible is still False?

Are you moving your labels in code? If so, is it possible you move your labels outside your container and that’s why you cannot see them?


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top