[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Question about control properties

Norm

8/22/2010 8:29:00 PM

Hi,

I am using the following code to set all controls on a form to visible,
so that I can set only the ones I want to see later in a routine, as
this seems the quickest and easiest way to do it when I only want to
see a few controls.

Code:

Dim ctl as Control

For Each ctl In Me.Controls
If Not TypeOf ctl Is Menu Then
ctl.Visible = False
End If
Next

The problem I don't understand is that the line ctl.Visible = False
generates and error that the object does not support this property or
method. If I put On Error Resume Next in the code it will contine and
will make all the controls not visible.

Is there some other way of coding this to either avoid the error or
some way of just trapping the error as it happens, without using On
Error Resume Next?

I have tried googling, but have not found anything explaining the
problem that I am having. Probably just not searching for the right
phrase. ;o)

Thanks,
Norm


48 Answers

GS

8/22/2010 8:52:00 PM

0

Norm formulated on Sunday :
> Hi,
>
> I am using the following code to set all controls on a form to visible, so
> that I can set only the ones I want to see later in a routine, as this seems
> the quickest and easiest way to do it when I only want to see a few controls.
>
> Code:
>
> Dim ctl as Control
>
> For Each ctl In Me.Controls
> If Not TypeOf ctl Is Menu Then
> ctl.Visible = False
> End If
> Next
>
> The problem I don't understand is that the line ctl.Visible = False generates
> and error that the object does not support this property or method. If I put
> On Error Resume Next in the code it will contine and will make all the
> controls not visible.
>
> Is there some other way of coding this to either avoid the error or some way
> of just trapping the error as it happens, without using On Error Resume Next?
>
> I have tried googling, but have not found anything explaining the problem
> that I am having. Probably just not searching for the right phrase. ;o)
>
> Thanks,
> Norm

Are there controls on the form that are not visible by default and
can't be set visible (ie: comctl32 or comdlg32)?

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


GS

8/22/2010 8:56:00 PM

0

GS brought next idea :
> Norm formulated on Sunday :
>> Hi,
>>
>> I am using the following code to set all controls on a form to visible, so
>> that I can set only the ones I want to see later in a routine, as this
>> seems the quickest and easiest way to do it when I only want to see a few
>> controls.
>>
>> Code:
>>
>> Dim ctl as Control
>>
>> For Each ctl In Me.Controls
>> If Not TypeOf ctl Is Menu Then
>> ctl.Visible = False
>> End If
>> Next
>>
>> The problem I don't understand is that the line ctl.Visible = False
>> generates and error that the object does not support this property or
>> method. If I put On Error Resume Next in the code it will contine and will
>> make all the controls not visible.
>>
>> Is there some other way of coding this to either avoid the error or some
>> way of just trapping the error as it happens, without using On Error Resume
>> Next?
>>
>> I have tried googling, but have not found anything explaining the problem
>> that I am having. Probably just not searching for the right phrase. ;o)
>>
>> Thanks,
>> Norm
>
> Are there controls on the form that are not visible by default and can't be
> set visible (ie: comctl32 or comdlg32)?

Actually, the comctl32 controls support a Visible property. The
comdlg32 control generates the error you report.

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Cor Ligthert [MVP]

8/22/2010 9:03:00 PM

0

Menu is not a member of controls.
http://msdn.microsoft.com/en-us/library/system.windows.forms...

Visibile is a property from Controls, so it can normally never go wrong with
the code which you show.

Is there maybe something more what can influence that it goes wrong..

A true menu can never be one of the form controls (menustrip can)


"Norm" <NormF4@Spoof.com> wrote in message
news:i4s1af$2jo$1@news.eternal-september.org...
> Hi,
>
> I am using the following code to set all controls on a form to visible, so
> that I can set only the ones I want to see later in a routine, as this
> seems the quickest and easiest way to do it when I only want to see a few
> controls.
>
> Code:
>
> Dim ctl as Control
>
> For Each ctl In Me.Controls
> If Not TypeOf ctl Is Menu Then
> ctl.Visible = False
> End If
> Next
>
> The problem I don't understand is that the line ctl.Visible = False
> generates and error that the object does not support this property or
> method. If I put On Error Resume Next in the code it will contine and will
> make all the controls not visible.
>
> Is there some other way of coding this to either avoid the error or some
> way of just trapping the error as it happens, without using On Error
> Resume Next?
>
> I have tried googling, but have not found anything explaining the problem
> that I am having. Probably just not searching for the right phrase. ;o)
>
> Thanks,
> Norm
>
>
>

Norm

8/22/2010 9:04:00 PM

0

GS wrote on 8/22/2010 :
> Norm formulated on Sunday :
>> Hi,
>>
>> I am using the following code to set all controls on a form to visible, so
>> that I can set only the ones I want to see later in a routine, as this
>> seems the quickest and easiest way to do it when I only want to see a few
>> controls.
>>
>> Code:
>>
>> Dim ctl as Control
>>
>> For Each ctl In Me.Controls
>> If Not TypeOf ctl Is Menu Then
>> ctl.Visible = False
>> End If
>> Next
>>
>> The problem I don't understand is that the line ctl.Visible = False
>> generates and error that the object does not support this property or
>> method. If I put On Error Resume Next in the code it will contine and will
>> make all the controls not visible.
>>
>> Is there some other way of coding this to either avoid the error or some
>> way of just trapping the error as it happens, without using On Error Resume
>> Next?
>>
>> I have tried googling, but have not found anything explaining the problem
>> that I am having. Probably just not searching for the right phrase. ;o)
>>
>> Thanks,
>> Norm
>
> Are there controls on the form that are not visible by default and can't be
> set visible (ie: comctl32 or comdlg32)?

I Dont' think so, I am only using controls from the Mscomctl.ocx, most
of them are lables, listboxes, checkboxes and cmboboxes. I have noticed
that when I type ctl. I do not get a list of options that I can select,
so was wondering if maybe I did not have a correct reference to
something or if this is normal when trying to manipulate controls. I am
able to change .visible = false to .name and get the names of all the
controls.

Norm


Norm

8/22/2010 9:10:00 PM

0

Cor explained on 8/22/2010 :
> Menu is not a member of controls.
> http://msdn.microsoft.com/en-us/library/system.windows.forms...
>
> Visibile is a property from Controls, so it can normally never go wrong with
> the code which you show.
>
> Is there maybe something more what can influence that it goes wrong..
>
> A true menu can never be one of the form controls (menustrip can)
>
>
> "Norm" <NormF4@Spoof.com> wrote in message
> news:i4s1af$2jo$1@news.eternal-september.org...
>> Hi,
>>
>> I am using the following code to set all controls on a form to visible, so
>> that I can set only the ones I want to see later in a routine, as this
>> seems the quickest and easiest way to do it when I only want to see a few
>> controls.
>>
>> Code:
>>
>> Dim ctl as Control
>>
>> For Each ctl In Me.Controls
>> If Not TypeOf ctl Is Menu Then
>> ctl.Visible = False
>> End If
>> Next
>>
>> The problem I don't understand is that the line ctl.Visible = False
>> generates and error that the object does not support this property or
>> method. If I put On Error Resume Next in the code it will contine and will
>> make all the controls not visible.
>>
>> Is there some other way of coding this to either avoid the error or some
>> way of just trapping the error as it happens, without using On Error Resume
>> Next?
>>
>> I have tried googling, but have not found anything explaining the problem
>> that I am having. Probably just not searching for the right phrase. ;o)
>>
>> Thanks,
>> Norm
>>
>>
>>

Cor,
The link you attached is not for VB6, which is what I am using. The
menus I am using are the ones created by VB6 at the top of a form. If
not excluded from the ctl.visible = False they will not show. So I
assume they are part of the controls class.

Norm


Abhishek

8/22/2010 10:26:00 PM

0

'Try this

On Error GoTo ErrHandle

Dim ctl As Control
For Each ctl In Me.Controls
If Not TypeOf ctl Is Menu Then
ctl.Visible = False
End If
Next

Exit Sub
ErrHandle:
Resume Next

--
VB6 Zone - Blog on Supporting VB6
http://vb6zone.bl...

Free usenet access at:
www.aioe.org
www.eternal-september.org

ClassicVB Users Regroup at:
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


GS

8/22/2010 10:32:00 PM

0

Cor brought next idea :
> Menu is not a member of controls.
> http://msdn.microsoft.com/en-us/library/system.windows.forms...
>
> Visibile is a property from Controls, so it can normally never go wrong with
> the code which you show.
>
> Is there maybe something more what can influence that it goes wrong..
>
> A true menu can never be one of the form controls (menustrip can)
>
>
> "Norm" <NormF4@Spoof.com> wrote in message
> news:i4s1af$2jo$1@news.eternal-september.org...
>> Hi,
>>
>> I am using the following code to set all controls on a form to visible, so
>> that I can set only the ones I want to see later in a routine, as this
>> seems the quickest and easiest way to do it when I only want to see a few
>> controls.
>>
>> Code:
>>
>> Dim ctl as Control
>>
>> For Each ctl In Me.Controls
>> If Not TypeOf ctl Is Menu Then
>> ctl.Visible = False
>> End If
>> Next
>>
>> The problem I don't understand is that the line ctl.Visible = False
>> generates and error that the object does not support this property or
>> method. If I put On Error Resume Next in the code it will contine and will
>> make all the controls not visible.
>>
>> Is there some other way of coding this to either avoid the error or some
>> way of just trapping the error as it happens, without using On Error Resume
>> Next?
>>
>> I have tried googling, but have not found anything explaining the problem
>> that I am having. Probably just not searching for the right phrase. ;o)
>>
>> Thanks,
>> Norm
>>
>>
>>

I tested both the menu controls added via Menu Editor, AND some of the
standard controls from the toolbox. Removing 'Not' from the If
construct causes all controls to not be visible. Leaving 'Not' in the
If construct only causes the standard controls to not be visible. No
error occurred in either test.

When I added comdlg32 to the form I got the same error as Norm. This
concludes that there must be a control on the form that does not have a
Visible property.

--
Garry

Free usenet access at http://www.eternal-sep...
ClassicVB Users Regroup! comp.lang.basic.visual.misc


ralph

8/22/2010 10:34:00 PM

0

On Sun, 22 Aug 2010 13:29:00 -0700, Norm <NormF4@Spoof.com> wrote:

>Hi,
>
>I am using the following code to set all controls on a form to visible,
>so that I can set only the ones I want to see later in a routine, as
>this seems the quickest and easiest way to do it when I only want to
>see a few controls.
>
>Code:
>
>Dim ctl as Control
>
> For Each ctl In Me.Controls
> If Not TypeOf ctl Is Menu Then
> ctl.Visible = False
> End If
> Next
>
>The problem I don't understand is that the line ctl.Visible = False
>generates and error that the object does not support this property or
>method. If I put On Error Resume Next in the code it will contine and
>will make all the controls not visible.
>
>Is there some other way of coding this to either avoid the error or
>some way of just trapping the error as it happens, without using On
>Error Resume Next?
>

You could place a "Select Case" or a series of "If...End If"s for each
type of control and only call a Visible method for a control type that
supports it.

However, there is nothing wrong with using an Error Statement in this
case - and Error Resume Next is probably the most elegant way to
handle it. Think of VB's 'structured' Error Handling as an early form
of a "Try ... Catch" block. The block is defined by each On Error
statement, and you can nest them.

Remember to reset the error handler to something else or 'back-again'
coming out of the loop, if you have additional code in the same
routine, and Resume/Next would not be an appropriate response.

>I have tried googling, but have not found anything explaining the
>problem that I am having. Probably just not searching for the right
>phrase. ;o)

Not that it makes that much difference, but what you are using is not
a "Control Array", it is the "Forms.Control Collection".

-ralph

Norm

8/22/2010 11:02:00 PM

0

It happens that ralph formulated :
> On Sun, 22 Aug 2010 13:29:00 -0700, Norm <NormF4@Spoof.com> wrote:
>
>> Hi,
>>
>> I am using the following code to set all controls on a form to visible,
>> so that I can set only the ones I want to see later in a routine, as
>> this seems the quickest and easiest way to do it when I only want to
>> see a few controls.
>>
>> Code:
>>
>> Dim ctl as Control
>>
>> For Each ctl In Me.Controls
>> If Not TypeOf ctl Is Menu Then
>> ctl.Visible = False
>> End If
>> Next
>>
>> The problem I don't understand is that the line ctl.Visible = False
>> generates and error that the object does not support this property or
>> method. If I put On Error Resume Next in the code it will contine and
>> will make all the controls not visible.
>>
>> Is there some other way of coding this to either avoid the error or
>> some way of just trapping the error as it happens, without using On
>> Error Resume Next?
>>
>
> You could place a "Select Case" or a series of "If...End If"s for each
> type of control and only call a Visible method for a control type that
> supports it.
>
> However, there is nothing wrong with using an Error Statement in this
> case - and Error Resume Next is probably the most elegant way to
> handle it. Think of VB's 'structured' Error Handling as an early form
> of a "Try ... Catch" block. The block is defined by each On Error
> statement, and you can nest them.
>
> Remember to reset the error handler to something else or 'back-again'
> coming out of the loop, if you have additional code in the same
> routine, and Resume/Next would not be an appropriate response.
>
>> I have tried googling, but have not found anything explaining the
>> problem that I am having. Probably just not searching for the right
>> phrase. ;o)
>
> Not that it makes that much difference, but what you are using is not
> a "Control Array", it is the "Forms.Control Collection".
>
> -ralph

Thanks for all the suggestions, I will separate the types of controls
in the loop and see if I can find which one is causing the error. If
nothing else I can put On Error Resume Next right before the loop,
Err.clear after the loop and an On Error GoTo statement after the loop.
It is probably not the best way to work, but I try to get my code to
work with no error trapping first, it helps point out all my mistakes.
:D

Norm


Abhishek

8/22/2010 11:10:00 PM

0

not before the loop but inside it, use this or see my previous post.

Dim ctl As Control
For Each ctl In Me.Controls
If Not TypeOf ctl Is Menu Then
On Error Resume Next
ctl.Visible = False
End If
Next



"Norm" <NormF4@Spoof.com> wrote in message
news:i4sa90$skb$1@news.eternal-september.org...
appropriate response.

| nothing else I can put On Error Resume Next right before the loop