INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Control Array Vuible property not being set

Control Array Vuible property not being set

(OP)
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

RE: Control Array Vuible property not being set

Do you have Option Explicit on the top of your code?
How is your control 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.

RE: Control Array Vuible property not being set

(OP)


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

RE: Control Array Vuible property not being set

(Please use code Tags to show your code) - again

Also, please do not TYPE your code in here, copy and paste it.
cntrol is not declared here, your 'Run with Full Compile' should not work.
control 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(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 

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.

RE: Control Array Vuible property not being set

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)

RE: Control Array Vuible property not being set

(OP)
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.

RE: Control Array Vuible property not being set

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
    If TypeOf cntr Is Label Then
        With cntr
            .Visible = True
            .Enabled = True
            .Tag = .Tag & ";Visible"
        End With
    End If
Next 

This code will loop thru all controls on the Form, and only for Labels 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.

RE: Control Array Vuible property not being set

>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."

RE: Control Array Vuible property not being set

(OP)
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

RE: Control Array Vuible property not being set

Can't say what is happening, then. On my dev box I can only replicate1 the reported behaviour if the container for picSG15But is not visible. If it is, then the code works exactly as expected.

1And 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

RE: Control Array Vuible property not being set

(OP)
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.

RE: Control Array Vuible property not being set

(Please use code Tags to show your code) - again, and again and again sad

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.

RE: Control Array Vuible property not being set

(OP)
Thank you for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close