Home All Groups Group Topic Archive Search About

Question about control properties

Author
22 Aug 2010 8:29 PM
Norm
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

Author
22 Aug 2010 8:52 PM
GS
Norm formulated on Sunday :
Show quoteHide quote
> 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-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Author
22 Aug 2010 8:56 PM
GS
GS brought next idea :
Show quoteHide quote
> 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-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Author
22 Aug 2010 9:04 PM
Norm
GS wrote on 8/22/2010 :
Show quoteHide quote
> 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
Author
22 Aug 2010 9:02 PM
Cor
Menu is not a member of controls.
http://msdn.microsoft.com/en-us/library/system.windows.forms.menu.aspx

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)


Show quoteHide quote
"Norm" <Nor***@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
>
>
>
Author
22 Aug 2010 9:09 PM
Norm
Cor explained on 8/22/2010 :
Show quoteHide quote
> Menu is not a member of controls.
> http://msdn.microsoft.com/en-us/library/system.windows.forms.menu.aspx
>
> 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" <Nor***@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
Author
23 Aug 2010 7:04 AM
Cor
Norm,

I had the idea I was reading your question in another newsgroup.

Something confused me yesterday.

Sorry,

Cor

Show quoteHide quote
"Norm" <Nor***@Spoof.com> wrote in message
news:i4s3mt$d75$1@news.eternal-september.org...
> Cor explained on 8/22/2010 :
>> Menu is not a member of controls.
>> http://msdn.microsoft.com/en-us/library/system.windows.forms.menu.aspx
>>
>> 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" <Nor***@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
>
>
>
Author
23 Aug 2010 9:33 AM
Mike Williams
"Cor" <Notmyfirstn***@planet.nl> wrote in message
news:%23EjnpFpQLHA.1712@TK2MSFTNGP05.phx.gbl...

> I had the idea I was reading your question in another
> newsgroup. Something confused me yesterday.

Something certainly did confuse you yesterday Cor, and in fact almost every
day for the last few months if the evidence of your constant trolling of
this group is anything to go by.You're a very naughty boy, Cor. You deserve
a good spanking. In fact I would arrange for somebody [small "s"] to give
you one were it not for the fact I think you would probably enjoy it.

Mike
Author
23 Aug 2010 9:41 AM
Mike Williams
Show quote Hide quote
"Mike Williams" <M***@WhiskyAndCoke.com> wrote in message
news:i4tf8f$2gc$1@speranza.aioe.org...
>
> "Cor" <Notmyfirstn***@planet.nl> wrote in message
> news:%23EjnpFpQLHA.1712@TK2MSFTNGP05.phx.gbl...
>
>> I had the idea I was reading your question in another
>> newsgroup. Something confused me yesterday.
>
> Something certainly did confuse you yesterday Cor, and in fact almost
> every day for the last few months if the evidence of your constant
> trolling of this group is anything to go by.You're a very naughty boy,
> Cor. You deserve a good spanking. In fact I would arrange for somebody
> [small "s"] to give you one were it not for the fact I think you would
> probably enjoy it.
>
> Mike

Actually we don't have a Somebody here, so there was no need for me to
emphasise the small "s". For a moment I thought Nobody was Somebody, but of
course he is not ;-)

Mike
Author
23 Aug 2010 11:25 AM
Kevin Provance
"Cor" <Notmyfirstn***@planet.nl> wrote in message
news:%23EjnpFpQLHA.1712@TK2MSFTNGP05.phx.gbl...
: Norm,
:
: I had the idea I was reading your question in another newsgroup.
:
: Something confused me yesterday.
:

Ah, the Tom Shelton excuse.  FAIL.  No one buys that one anymore, especially
since the MSFT web forum and Usenet are COMPLETELY DIFFERENT!!!!

Troll.
Author
25 Aug 2010 4:08 PM
Dee Earley
On 23/08/2010 12:25, Kevin Provance wrote:
>
> "Cor"<Notmyfirstn***@planet.nl>  wrote in message
> news:%23EjnpFpQLHA.1712@TK2MSFTNGP05.phx.gbl...
> : Norm,
> :
> : I had the idea I was reading your question in another newsgroup.
> :
> : Something confused me yesterday.
> :
>
> Ah, the Tom Shelton excuse.  FAIL.  No one buys that one anymore, especially
> since the MSFT web forum and Usenet are COMPLETELY DIFFERENT!!!!

Who says the web forum is the only place to talk about .net?
There are still other groups around...

--
Dee Earley (dee.ear***@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
Author
25 Aug 2010 11:30 PM
Henning
Show quote Hide quote
"Dee Earley" <dee.ear***@icode.co.uk> skrev i meddelandet
news:%23jDkMBHRLHA.4996@TK2MSFTNGP04.phx.gbl...
> On 23/08/2010 12:25, Kevin Provance wrote:
>>
>> "Cor"<Notmyfirstn***@planet.nl>  wrote in message
>> news:%23EjnpFpQLHA.1712@TK2MSFTNGP05.phx.gbl...
>> : Norm,
>> :
>> : I had the idea I was reading your question in another newsgroup.
>> :
>> : Something confused me yesterday.
>> :
>>
>> Ah, the Tom Shelton excuse.  FAIL.  No one buys that one anymore,
>> especially
>> since the MSFT web forum and Usenet are COMPLETELY DIFFERENT!!!!
>
> Who says the web forum is the only place to talk about .net?
> There are still other groups around...
>
> --
> Dee Earley (dee.ear***@icode.co.uk)
> i-Catcher Development Team
>
> iCode Systems
>
> (Replies direct to my email address will be ignored.
> Please reply to the group.)

See anyone interested?

/Henning
Author
25 Aug 2010 11:45 PM
Tom Shelton
Dee Earley brought next idea :
Show quoteHide quote
> On 23/08/2010 12:25, Kevin Provance wrote:
>>
>> "Cor"<Notmyfirstn***@planet.nl>  wrote in message
>> news:%23EjnpFpQLHA.1712@TK2MSFTNGP05.phx.gbl...
>> : Norm,
>> :
>> : I had the idea I was reading your question in another newsgroup.
>> :
>> : Something confused me yesterday.
>> :
>>
>> Ah, the Tom Shelton excuse.  FAIL.  No one buys that one anymore,
>> especially
>> since the MSFT web forum and Usenet are COMPLETELY DIFFERENT!!!!
>
> Who says the web forum is the only place to talk about .net?
> There are still other groups around...

What he calls the "Tom Shelton" excuse, well, yes it did happen a
couple of times - maybe twice in the last 3 or 4 years.

Kevin seems not to realize that some people actually read more then one
news group.  And sometimes, especially when they are about similar
topics you can forget which group you are in.  It was especially easy
in my old console based news reader slrn (which I miss dearly, but
crashes when attempting to connect to eternal-septembers servers).

--
Tom Shelton
Author
26 Aug 2010 12:41 AM
Kevin Provance
"Tom Shelton" <tom_shelton@comcast.invalid> wrote in message
news:i549v1$8r5$1@news.eternal-september.org...

: Kevin seems not to realize that some people actually read more then one
: news group.  And sometimes, especially when they are about similar
: topics you can forget which group you are in.  It was especially easy
: in my old console based news reader slrn (which I miss dearly, but
: crashes when attempting to connect to eternal-septembers servers).

Wrong Ray.  Kevin realizes that trolls like you and Cory like to use this
excuse to drop your plugs.  Choice of newsreader has nothing to do with it.
Would anyone in that social group you get your panties wet over really
believe it if I answered a question in VB6 code and then "whoops, wrong
group.  My bad."

No, I don't think so.  While I recognize the lot of you are...well, dummies,
the dummy card isn't working.  Perhaps Cory can try the race card next time.

How's that 67 Beetle doing?  Get it out of Barb's driveway yet?
Author
26 Aug 2010 1:03 AM
Tom Shelton
After serious thinking Kevin Provance wrote :
> "Tom Shelton" <tom_shelton@comcast.invalid> wrote in message
> news:i549v1$8r5$1@news.eternal-september.org...
>
>> Kevin seems not to realize that some people actually read more then one
>> news group.  And sometimes, especially when they are about similar
>> topics you can forget which group you are in.  It was especially easy
>> in my old console based news reader slrn (which I miss dearly, but
>> crashes when attempting to connect to eternal-septembers servers).
>
> Wrong Ray.  Kevin realizes that trolls like you and Cory like to use this
> excuse to drop your plugs.  Choice of newsreader has nothing to do with it.

Kevin - if this was a common occurance, then I'm sure you can prove
that I have done it often...  Oh, wait - you still haven't come up with
anything since the last time we had this discussion...

> Would anyone in that social group you get your panties wet over really
> believe it if I answered a question in VB6 code and then "whoops, wrong
> group.  My bad."

If your talking about the web forums, I hate those.  I use them, but I
hate them.  Always have.  If I didn't I would have given up on usnet a
long time ago.  I left the old devx groups, when they went totally
web...

And, there is a big difference between a newsreader - especially my old
one that was totally text based (used console version of vim as the
editor) and a web forum.

--
Tom Shelton
Author
22 Aug 2010 10:31 PM
GS
Cor brought next idea :
Show quoteHide quote
> Menu is not a member of controls.
> http://msdn.microsoft.com/en-us/library/system.windows.forms.menu.aspx
>
> 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" <Nor***@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-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Author
23 Aug 2010 12:13 AM
Kevin Provance
"Cor" <Notmyfirstn***@planet.nl> wrote in message
news:%23zg3f1jQLHA.2100@TK2MSFTNGP04.phx.gbl...
: Menu is not a member of controls.
: http://msdn.microsoft.com/en-us/library/system.windows.forms.menu.aspx
:
: 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)

He's using VB6, numbwit.  You're in the wrong place, as usual, pasty face.
Author
22 Aug 2010 10:26 PM
Abhishek
'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.blogspot.com

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
Author
22 Aug 2010 10:33 PM
ralph
On Sun, 22 Aug 2010 13:29:00 -0700, Norm <Nor***@Spoof.com> wrote:

Show quoteHide quote
>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
Author
22 Aug 2010 11:01 PM
Norm
It happens that ralph formulated :
Show quoteHide quote
> On Sun, 22 Aug 2010 13:29:00 -0700, Norm <Nor***@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
Author
22 Aug 2010 11:09 PM
Abhishek
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



Show quoteHide quote
"Norm" <Nor***@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
Author
23 Aug 2010 12:16 AM
Kevin Provance
"Abhishek" <abhishek0***@hotmail.com> wrote in message
news:i4sanm$bq7$1@speranza.aioe.org...
: 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

Why would you do this?  It makes no sense.  At no point are you setting the
error handler back "on", so to speak. So constantly turning it off it
redundant.

Setting up a proper error handling routine or switching the whole smack off
is a better idea.
Author
23 Aug 2010 1:13 AM
Nobody
Show quote Hide quote
"Kevin Provance" <c@k.p> wrote in message
news:i4sel2$54t$1@news.eternal-september.org...
>
> "Abhishek" <abhishek0***@hotmail.com> wrote in message
> news:i4sanm$bq7$1@speranza.aioe.org...
> : 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
>
> Why would you do this?  It makes no sense.  At no point are you setting
> the
> error handler back "on", so to speak. So constantly turning it off it
> redundant.
>
> Setting up a proper error handling routine or switching the whole smack
> off
> is a better idea.

I think what Abhishek is trying to achieve is making sure that Err object is
clear before the routine ends. His first suggestion works, but this one
doesn't. Here is what I suggest:

On Error Resume Next

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

Err.Clear

It's "necessary" to call Err.Clear before retuning to the caller, otherwise
the caller would see the last Err.Number and might screw up the logic that
it's using especially if it's using "On Error Resume Next" too. I suppose
this depends on style of coding. Below is an example of what I am talking
about. In Form_Load, I am using "On Error Resume Next", and I am also
calling a Test() Sub, which also has "On Error Resume Next" to "suppress"
errors.

First, Form_Load calls Test() sub, then an error occurs in Test() sub, after
it returns, Err.Object is still carrying the old values, and later when I
open an existing text file for Input, and check for errors, I see the error
that was generated in Test() sub, which I supposedly suppressed with "On
Error Resume Next". The file exists, and I am running as Admin in XP. Here
the sample code. You need to create a file called "C:\test.txt" before
running the sample.

Private Sub Form_Load()
    Dim f As Long

    On Error Resume Next

    Test

    Debug.Print "Err.Number is " & Err.Number & ": " & Err.Description

    f = FreeFile
    Open "C:\test.txt" For Input As f
    If Err.Number <> 0 Then
        Debug.Print "Error opening file. Err.Number is " & Err.Number & _
            ": " & Err.Description
    End If
    Close f

End Sub

Output(The file exists and opens fine):

Err.Number is 6: Overflow
Error opening file. Err.Number is 6: Overflow

Note that Open statement above doesn't really generates an error, the next
line sees the ghost left by Test() sub, so the solution is to use Err.Clear
after calling Test(), or before using Open statement, or insuring that Test
uses Err.Clear before exiting.
Author
23 Aug 2010 1:44 AM
Nobody
I forgot to include the whole sample, here it is again:

Option Explicit

Private Sub Form_Load()
    Dim f As Long

    On Error Resume Next

    Test

    Debug.Print "Err.Number is " & Err.Number & ": " & Err.Description

    f = FreeFile
    Open "C:\test.txt" For Input As f
    If Err.Number <> 0 Then
        Debug.Print "Error opening file. Err.Number is " & Err.Number & _
            ": " & Err.Description
    End If
    Close f

End Sub

Private Sub Test()
    Dim i As Long

    On Error Resume Next

    i = i / 0

End Sub


Output when the file is present:

Err.Number is 6: Overflow
Error opening file. Err.Number is 6: Overflow

Output when I add "Err.Clear" before Test exits:

Err.Number is 0:
Author
23 Aug 2010 3:09 AM
ralph
Show quote Hide quote
On Sun, 22 Aug 2010 21:13:11 -0400, "Nobody" <nob***@nobody.com>
wrote:


>I think what Abhishek is trying to achieve is making sure that Err object is
>clear before the routine ends. His first suggestion works, but this one
>doesn't. Here is what I suggest:
>
>On Error Resume Next
>
>Dim ctl As Control
>For Each ctl In Me.Controls
>    If Not TypeOf ctl Is Menu Then
>        ctl.Visible = False
>    End If
>Next
>
>Err.Clear
>
>It's "necessary" to call Err.Clear before retuning to the caller, otherwise
>the caller would see the last Err.Number and might screw up the logic that
>it's using especially if it's using "On Error Resume Next" too. I suppose
>this depends on style of coding. ...


Setting a new active error handler makes the problem a non-issue,
because the Err object will definitely be reset on running into
another error. But obviously can fail if one attempted to test the Err
object in the meantime.

As long as one is very clear on the error blocks he is working with,
and manages any errors in an error handler, setting and resetting
error handlers will cause no problems.

However, you bring out an interesting point. Using a Resume Next,
since its purpose is to deliberately 'hide' an error, could possibly
lead to situation where you do in fact have a "dangling Err object".

But only if you go and peek. <g>
Notice that your sample does exactly what you told it to do - it
skipped any errors and happily went on to the next order of business.
In this case, not a particularly good idea, since Test() is in need of
some serious attention.

Your sample is more an example to be careful when using Resume Next,
because you will get what you asked for, and second be leery whenever
you start chewing on an Err object outside a handler - be sure you
know where it came from and how reliable it is.

Popping in an Err.Clear in lieu of setting a new active handler upon
leaving a block where Resume Next has been active certainly does no
harm, and might well prevent some surprises and thus is good advice.

-ralph
Author
22 Aug 2010 11:12 PM
Norm
Thanks again for all the suggestions and GS was right. lol

I don't know why I did not think of doing this before, but I put a
Debug.Print ctl.name right before the visible = false and found the
problem, actually two of them, as GS suggested.

I forgot I had a Timer and a ListImage on the form, both of those
created the error, so I just used:

    For Each ctl In Me.Controls
        If Not TypeOf ctl Is Menu Then
            If TypeOf ctl Is Timer Or TypeOf ctl Is ImageList Then
            Else
                'Debug.Print ctl.name
                ctl.Visible = False
            End If
        End If
    Next

and solved the problem.

Thanks again,
Norm
Author
23 Aug 2010 12:40 AM
ralph
On Sun, 22 Aug 2010 16:12:46 -0700, Norm <Nor***@Spoof.com> wrote:

Show quoteHide quote
>Thanks again for all the suggestions and GS was right. lol
>
>I don't know why I did not think of doing this before, but I put a
>Debug.Print ctl.name right before the visible = false and found the
>problem, actually two of them, as GS suggested.
>
>I forgot I had a Timer and a ListImage on the form, both of those
>created the error, so I just used:
>
>    For Each ctl In Me.Controls
>        If Not TypeOf ctl Is Menu Then
>            If TypeOf ctl Is Timer Or TypeOf ctl Is ImageList Then
>            Else
>                'Debug.Print ctl.name
>                ctl.Visible = False
>            End If
>        End If
>    Next
>
>and solved the problem.
>

There is often no right or wrong method if it produces the desired
result. Everything in programming is a matter of trade-offs and
ultimately dependent on the comfort-level of the programmer.

But consider this. You can have a simple loop that interrogates the
Control collection, then sets those with a Visible property to false.

With your new solution you have avoiding using structured error
handling, BUT now you have created a routine that interrogates the
collection, determines the types to skip, and sets those that don't
match the "skip conditional" to False. In other words you have not
only added more lines - you have introduced a dependency.

What happens if you add new control types?
What if you decided to use this routine with another form?

-ralph
Author
23 Aug 2010 6:14 AM
GS
After serious thinking Norm wrote :
Show quoteHide quote
> Thanks again for all the suggestions and GS was right. lol
>
> I don't know why I did not think of doing this before, but I put a
> Debug.Print ctl.name right before the visible = false and found the problem,
> actually two of them, as GS suggested.
>
> I forgot I had a Timer and a ListImage on the form, both of those created the
> error, so I just used:
>
>     For Each ctl In Me.Controls
>         If Not TypeOf ctl Is Menu Then
>             If TypeOf ctl Is Timer Or TypeOf ctl Is ImageList Then
>             Else
>                 'Debug.Print ctl.name
>                 ctl.Visible = False
>             End If
>         End If
>     Next
>
> and solved the problem.
>
> Thanks again,
> Norm

Just a suggestion for the sake of simplicity...
Is there any reason why you can't put the controls you want to
manipulate in a container (ie: a frame) and just loop that container's
controls? This way your utility controls are not included.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Author
23 Aug 2010 6:54 AM
Andrew
On 23/08/2010 4:14 PM, GS wrote:
Show quoteHide quote
> After serious thinking Norm wrote :
>> Thanks again for all the suggestions and GS was right. lol
>>
>> I don't know why I did not think of doing this before, but I put a
>> Debug.Print ctl.name right before the visible = false and found the
>> problem, actually two of them, as GS suggested.
>>
>> I forgot I had a Timer and a ListImage on the form, both of those
>> created the error, so I just used:
>>
>> For Each ctl In Me.Controls
>> If Not TypeOf ctl Is Menu Then
>> If TypeOf ctl Is Timer Or TypeOf ctl Is ImageList Then
>> Else
>> 'Debug.Print ctl.name
>> ctl.Visible = False
>> End If
>> End If
>> Next
>>
>> and solved the problem.
>>
>> Thanks again,
>> Norm
>
> Just a suggestion for the sake of simplicity...
> Is there any reason why you can't put the controls you want to
> manipulate in a container (ie: a frame) and just loop that container's
> controls? This way your utility controls are not included.
>

Hi Norm,

I use this routine to enable and disable controls in a container. You
could modify it to the .Visible property instead of the .Enabled and
..Forecolor properties.

I use this when I have a "master" checkbox, which in turn, enables or
disables a Frame and it's child controls.

Might be a starting point...


'---------------------------------------------------------------------------------------
' Procedure  : SetChildrenEnabled
' DateTime   : 10/02/2010 12:14
' Author     : Andrew
' Purpose    : Enable or Disable controls in a Frame
' Arguments  : Obj: the container Frame, State to set, Set Container
Frame enabled also?
' Returns    : none
'---------------------------------------------------------------------------------------
'
Public Sub SetChildrenEnabled(obj As Object, State As Boolean, Optional
MeToo As Boolean)
Dim Ctl As Control

   On Local Error Resume Next

    For Each Ctl In obj.Parent.Controls
       If Ctl.Container Is obj Then
          If TypeOf Ctl Is Label Then
             If State Then
                Ctl.ForeColor = QBColor(0)
             Else
                Ctl.ForeColor = QBColor(8)
             End If
          ElseIf TypeOf Ctl Is Line Then
             If State Then
                Ctl.BorderColor = QBColor(0)
             Else
                Ctl.BorderColor = QBColor(8)
             End If
          ElseIf TypeOf Ctl Is Shape Then
             If State Then
                Ctl.BorderColor = QBColor(0)
             Else
                Ctl.BorderColor = QBColor(8)
             End If
          Else
             Ctl.Enabled = State
          End If
          If MeToo Then
             obj.Enabled = State
          End If
       End If
    Next Ctl

    Err.Number = 0

End Sub


Andrew
DynoLog Dynamometer
Australia
Author
23 Aug 2010 9:12 PM
Norm
Andrew submitted this idea :
Show quoteHide quote
> On 23/08/2010 4:14 PM, GS wrote:
>> After serious thinking Norm wrote :
>>> Thanks again for all the suggestions and GS was right. lol
>>>
>>> I don't know why I did not think of doing this before, but I put a
>>> Debug.Print ctl.name right before the visible = false and found the
>>> problem, actually two of them, as GS suggested.
>>>
>>> I forgot I had a Timer and a ListImage on the form, both of those
>>> created the error, so I just used:
>>>
>>> For Each ctl In Me.Controls
>>> If Not TypeOf ctl Is Menu Then
>>> If TypeOf ctl Is Timer Or TypeOf ctl Is ImageList Then
>>> Else
>>> 'Debug.Print ctl.name
>>> ctl.Visible = False
>>> End If
>>> End If
>>> Next
>>>
>>> and solved the problem.
>>>
>>> Thanks again,
>>> Norm
>>
>> Just a suggestion for the sake of simplicity...
>> Is there any reason why you can't put the controls you want to
>> manipulate in a container (ie: a frame) and just loop that container's
>> controls? This way your utility controls are not included.
>>
>
> Hi Norm,
>
> I use this routine to enable and disable controls in a container. You could
> modify it to the .Visible property instead of the .Enabled and
> .Forecolor properties.
>
> I use this when I have a "master" checkbox, which in turn, enables or
> disables a Frame and it's child controls.
>
> Might be a starting point...
>
>
> '---------------------------------------------------------------------------------------
> ' Procedure  : SetChildrenEnabled
> ' DateTime   : 10/02/2010 12:14
> ' Author     : Andrew
> ' Purpose    : Enable or Disable controls in a Frame
> ' Arguments  : Obj: the container Frame, State to set, Set Container Frame
> enabled also?
> ' Returns    : none
> '---------------------------------------------------------------------------------------
> '
> Public Sub SetChildrenEnabled(obj As Object, State As Boolean, Optional MeToo
> As Boolean)
> Dim Ctl As Control
>
>    On Local Error Resume Next
>
>     For Each Ctl In obj.Parent.Controls
>        If Ctl.Container Is obj Then
>           If TypeOf Ctl Is Label Then
>              If State Then
>                 Ctl.ForeColor = QBColor(0)
>              Else
>                 Ctl.ForeColor = QBColor(8)
>              End If
>           ElseIf TypeOf Ctl Is Line Then
>              If State Then
>                 Ctl.BorderColor = QBColor(0)
>              Else
>                 Ctl.BorderColor = QBColor(8)
>              End If
>           ElseIf TypeOf Ctl Is Shape Then
>              If State Then
>                 Ctl.BorderColor = QBColor(0)
>              Else
>                 Ctl.BorderColor = QBColor(8)
>              End If
>           Else
>              Ctl.Enabled = State
>           End If
>           If MeToo Then
>              obj.Enabled = State
>           End If
>        End If
>     Next Ctl
>
>     Err.Number = 0
>
> End Sub
>
>
> Andrew
> DynoLog Dynamometer
> Australia

Andrew,
Thanks for the suggestion, I have a lot of things to look at and study
now. I am going to try Helmut's solution as it seems so simple.

Norm
Author
23 Aug 2010 12:15 AM
ralph
On Sun, 22 Aug 2010 16:01:47 -0700, Norm <Nor***@Spoof.com> wrote:


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

Always a useful exercise.

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

Get the - "It is probably not the best way to work" thinking - out of
your head. <g>

Obviously the fewest number of constructs one uses to produce a
reliable result the better in terms of "elegance" and "performance"
your code will be. Structured Error Handling is just one of many
constructs at your disposal. Like all programming constructs it can be
abused, but it can also be the most logical way to manage a given
solution as well as simplify the construction.

-ralph
Author
23 Aug 2010 12:50 AM
Norm
ralph brought next idea :
Show quoteHide quote
> On Sun, 22 Aug 2010 16:01:47 -0700, Norm <Nor***@Spoof.com> wrote:
>
>
>>
>> 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.
>
> Always a useful exercise.
>
>> ... 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
>
> Get the - "It is probably not the best way to work" thinking - out of
> your head. <g>
>
> Obviously the fewest number of constructs one uses to produce a
> reliable result the better in terms of "elegance" and "performance"
> your code will be. Structured Error Handling is just one of many
> constructs at your disposal. Like all programming constructs it can be
> abused, but it can also be the most logical way to manage a given
> solution as well as simplify the construction.
>
> -ralph

Ralph,

Thanks for all the information. Could you show me some code on how you
would use this so that I might better understand Structured Error
Handling.

Thanks
Norm
Author
23 Aug 2010 1:10 AM
Kevin Provance
"Norm" <Nor***@Spoof.com> wrote in message
news:i4sgle$2c1$1@news.eternal-september.org...

: Thanks for all the information. Could you show me some code on how you
: would use this so that I might better understand Structured Error
: Handling.

I guess googling it for yourself would be too difficult, huh?

Function DoWhatever()

On Error Goto ErrorTrap

<your code>

Exit Function

ErrorTrap:
<do whatever you need to here>

End Function

Not rocket science.
Author
23 Aug 2010 1:24 AM
Norm
Kevin Provance pretended :
Show quoteHide quote
> "Norm" <Nor***@Spoof.com> wrote in message
> news:i4sgle$2c1$1@news.eternal-september.org...
>
>> Thanks for all the information. Could you show me some code on how you
>> would use this so that I might better understand Structured Error
>> Handling.
>
> I guess googling it for yourself would be too difficult, huh?
>
> Function DoWhatever()
>
> On Error Goto ErrorTrap
>
> <your code>
>
> Exit Function
>
> ErrorTrap:
> <do whatever you need to here>
>
> End Function
>
> Not rocket science.

I can do that Kevin, but that is using error trapping for the entire
sub routine, which I do. I was trying to avoid changing just for the
loop, which you would have to do or have two different error routines,
which I guess would make sense also.

I show a message with my error routine's, but could use a second one
just for that loop without a message, but it would probably make just
as much sense to put On Error Resume Next just before the loop then
after the loop use Err.clear
and On Error GoTo again.

I got the impression Ralph was talking about a routine just for that
loop and was hoping to be able to insert it inside that loop.

Norm
Author
23 Aug 2010 11:42 AM
Helmut Meukel
Am 23.08.2010, Norm wrote :
Show quoteHide quote
> I can do that Kevin, but that is using error trapping for the entire sub
> routine, which I do. I was trying to avoid changing just for the loop, which
> you would have to do or have two different error routines, which I guess
> would make sense also.
>
> I show a message with my error routine's, but could use a second one just for
> that loop without a message, but it would probably make just as much sense to
> put On Error Resume Next just before the loop then after the loop use
> Err.clear
> and On Error GoTo again.
>
> I got the impression Ralph was talking about a routine just for that loop and
> was hoping to be able to insert it inside that loop.
>

If you put the loop into a sepatate subroutine then the error handling
for the loop wouldn't affect the other code or am I overlooking
something?

Helmut.
Author
23 Aug 2010 9:11 PM
Norm
Helmut Meukel formulated on Monday :
Show quoteHide quote
> Am 23.08.2010, Norm wrote :
>> I can do that Kevin, but that is using error trapping for the entire sub
>> routine, which I do. I was trying to avoid changing just for the loop,
>> which you would have to do or have two different error routines, which I
>> guess would make sense also.
>>
>> I show a message with my error routine's, but could use a second one just
>> for that loop without a message, but it would probably make just as much
>> sense to put On Error Resume Next just before the loop then after the loop
>> use Err.clear
>> and On Error GoTo again.
>>
>> I got the impression Ralph was talking about a routine just for that loop
>> and was hoping to be able to insert it inside that loop.
>>
>
> If you put the loop into a sepatate subroutine then the error handling
> for the loop wouldn't affect the other code or am I overlooking
> something?
>
> Helmut.

Helmut,

What a simple solution, case of not seeing the forest for the trees.
lol

Thanks,
Norm
Author
23 Aug 2010 2:04 AM
ralph
On Sun, 22 Aug 2010 17:50:49 -0700, Norm <Nor***@Spoof.com> wrote:


>
>Thanks for all the information. Could you show me some code on how you
>would use this so that I might better understand Structured Error
>Handling.
>

   Public Sub SomeSub()   
    ' set an active error handler
   On Error Goto SomeSub_Err
         ...
            ' doing stuff
         ...
            ' going into the loop
       Dim ctl as Control
            ' set a new active error handler
       On Error Resume Next
       For Each ctl In Me.Controls
       If Not TypeOf ctl Is Menu Then
            ctl.Visible = False
       End If
           ' set active error handler
           ' in this case the old one, but it could just as easily
           ' be something new
       On Error Goto SomeSub_Err
         ...
       Exit Sub
       SomeSub_Err:
          Debug.Assert False   ' for development
          ...
  End Sub


The MSDN Help contains all the information you need. Anything I might
say would be repeating the documentation and perhaps 'badly'. <g>

However, you might find these sources of additional interest:

For an interesting view also pointing out IDE debug options:
"Error Handling and Debugging Tips and Techniques for Microsoft
Access, VBA, and Visual Basic 6 (VB6)"
http://www.fmsinc.com/tpapers/vbacode/Debug.asp

A different documenation from the horse's mouth:
"Error Handling Hierarchy"
http://msdn.microsoft.com/en-us/library/aa241677%28VS.60%29.aspx

Also if you are not using it, I strongly recommend you download the
MZ-Tools addon.
http://www.mztools.com/v3/download.aspx

This addon will automatically generate error handler templates and add
or remove line numbers (an exceptionally useful technique at times).
As well as a ton of other useful utilities MS left out of the IDE.

IMHO it is a manditory VB development tool.

I as a matter of habit I always use a template which creates error
handling automatically during development (except for perhaps the most
trivial, but definitely for events) with the Debug.Assert statement I
showed above.

This is a tad silly in that simply allowing an error to be thrown and
caught by the IDE which immediately places you at the point of the
offending code is just as easy (or even easier), but note the Error
Options in the IDE - sometimes it is just as useful to test the error
handler.

I go back later and clean-out what I feel is unnecessary.

-ralph
Author
23 Aug 2010 4:39 AM
Norm
ralph explained :
Show quoteHide quote
> On Sun, 22 Aug 2010 17:50:49 -0700, Norm <Nor***@Spoof.com> wrote:
>
>
>>
>> Thanks for all the information. Could you show me some code on how you
>> would use this so that I might better understand Structured Error
>> Handling.
>>
>
>    Public Sub SomeSub()   
>     ' set an active error handler
>    On Error Goto SomeSub_Err
>          ...
>             ' doing stuff
>          ...
>             ' going into the loop
>        Dim ctl as Control
>             ' set a new active error handler
>        On Error Resume Next
>        For Each ctl In Me.Controls
>        If Not TypeOf ctl Is Menu Then
>             ctl.Visible = False
>        End If
>            ' set active error handler
>            ' in this case the old one, but it could just as easily
>            ' be something new
>        On Error Goto SomeSub_Err
>          ...
>        Exit Sub
>        SomeSub_Err:
>           Debug.Assert False   ' for development
>           ...
>   End Sub
>
>
> The MSDN Help contains all the information you need. Anything I might
> say would be repeating the documentation and perhaps 'badly'. <g>
>
> However, you might find these sources of additional interest:
>
> For an interesting view also pointing out IDE debug options:
> "Error Handling and Debugging Tips and Techniques for Microsoft
> Access, VBA, and Visual Basic 6 (VB6)"
> http://www.fmsinc.com/tpapers/vbacode/Debug.asp
>
> A different documenation from the horse's mouth:
> "Error Handling Hierarchy"
> http://msdn.microsoft.com/en-us/library/aa241677%28VS.60%29.aspx
>
> Also if you are not using it, I strongly recommend you download the
> MZ-Tools addon.
> http://www.mztools.com/v3/download.aspx
>
> This addon will automatically generate error handler templates and add
> or remove line numbers (an exceptionally useful technique at times).
> As well as a ton of other useful utilities MS left out of the IDE.
>
> IMHO it is a manditory VB development tool.
>
> I as a matter of habit I always use a template which creates error
> handling automatically during development (except for perhaps the most
> trivial, but definitely for events) with the Debug.Assert statement I
> showed above.
>
> This is a tad silly in that simply allowing an error to be thrown and
> caught by the IDE which immediately places you at the point of the
> offending code is just as easy (or even easier), but note the Error
> Options in the IDE - sometimes it is just as useful to test the error
> handler.
>
>  I go back later and clean-out what I feel is unnecessary.
>
> -ralph

Ralph,
Thanks for the information. The example you show is what I have done in
the past, but assumed that there might be a better way of handling the
setting of the controls, so that I would not need to put a specific
error handler in the loop. I usually assume that when I get an error
that I have done something wrong and then look for a way to correct the
problem. That approach does not always work though. :D

I will read all the information that is in the links that you included,
as I do need to learn a lot more about error handling. I have not used
MzTools, but do have a program called CodeSmart, which also includes
error handling templets and I do use them.

Thanks for all the information.

Norm
Author
25 Aug 2010 12:05 PM
phil hunt
As a side question, is there a way to revert a property to it's design time
property later on ?




Show quoteHide quote
"Norm" <Nor***@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
>
>
Author
25 Aug 2010 4:04 PM
Norm
phil hunt presented the following explanation :
Show quoteHide quote
> As a side question, is there a way to revert a property to it's design time
> property later on ?
>
>
>
>
> "Norm" <Nor***@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
>>
>>

Phil,

If I understand your question correcty, you could store the the
property value you wanted to restore later in a variable before
changing it and then restore the variable later.

Norm
Author
25 Aug 2010 4:57 PM
Phil Hunt
I was hoping someone would tell me it is stored somewhere already, all I
need is to get it. Maybe not.
Author
25 Aug 2010 5:17 PM
Jack T.
API Function --->IsWindowVisible

http://msdn.microsoft.com/en-us/library/ms633530(VS.85).aspx

Show quoteHide quote
"Phil Hunt" <a**@aaa.com> wrote in message
news:%23KyMVaHRLHA.2068@TK2MSFTNGP05.phx.gbl...
>I was hoping someone would tell me it is stored somewhere already, all I
>need is to get it. Maybe not.
>
Author
25 Aug 2010 5:48 PM
Bob Butler
"Jack T." <anywh***@anywhere.com> wrote in message
news:OHuS0lHRLHA.2068@TK2MSFTNGP05.phx.gbl...
> API Function --->IsWindowVisible
>
> http://msdn.microsoft.com/en-us/library/ms633530(VS.85).aspx
>
> "Phil Hunt" <a**@aaa.com> wrote in message
> news:%23KyMVaHRLHA.2068@TK2MSFTNGP05.phx.gbl...
>>I was hoping someone would tell me it is stored somewhere already, all I
>>need is to get it. Maybe not.


Huh?
Author
25 Aug 2010 6:06 PM
VB 6 Devotee
You might try storing the initial value in the Tag property during the Form
Activate Event and then retrieve it later.

Show quoteHide quote
"Phil Hunt" <a**@aaa.com> wrote in message
news:%23KyMVaHRLHA.2068@TK2MSFTNGP05.phx.gbl...
>I was hoping someone would tell me it is stored somewhere already, all I
>need is to get it. Maybe not.
>
Author
25 Aug 2010 6:13 PM
Phil Hunt
There are tons of properties and only 1 tag.
Is there a way to re-load a control, that would get the design time prop .

Show quoteHide quote
"VB 6 Devotee" <h***@yomamma.com> wrote in message
news:%23wnt4AIRLHA.784@TK2MSFTNGP02.phx.gbl...
> You might try storing the initial value in the Tag property during the
> Form Activate Event and then retrieve it later.
>
> "Phil Hunt" <a**@aaa.com> wrote in message
> news:%23KyMVaHRLHA.2068@TK2MSFTNGP05.phx.gbl...
>>I was hoping someone would tell me it is stored somewhere already, all I
>>need is to get it. Maybe not.
>>
>
Author
25 Aug 2010 6:35 PM
Bob Butler
"Phil Hunt" <a**@aaa.com> wrote in message
news:eZhYFFIRLHA.2068@TK2MSFTNGP05.phx.gbl...
> There are tons of properties and only 1 tag.
> Is there a way to re-load a control, that would get the design time prop .

You could always add a non-visible control and use that to copy the
properties from
Author
25 Aug 2010 6:35 PM
VB 6 Devotee
Well, you could create a class with all the properties you want to save,
then store the class in a collection or an array.

Or you could try using a PropertyBag to save the data.
http://www.a1vbcode.com/snippet.asp?ID=754







Show quoteHide quote
"Phil Hunt" <a**@aaa.com> wrote in message
news:eZhYFFIRLHA.2068@TK2MSFTNGP05.phx.gbl...
> There are tons of properties and only 1 tag.
> Is there a way to re-load a control, that would get the design time prop .
>
> "VB 6 Devotee" <h***@yomamma.com> wrote in message
> news:%23wnt4AIRLHA.784@TK2MSFTNGP02.phx.gbl...
>> You might try storing the initial value in the Tag property during the
>> Form Activate Event and then retrieve it later.
>>
>> "Phil Hunt" <a**@aaa.com> wrote in message
>> news:%23KyMVaHRLHA.2068@TK2MSFTNGP05.phx.gbl...
>>>I was hoping someone would tell me it is stored somewhere already, all I
>>>need is to get it. Maybe not.
>>>
>>
>
>
Author
25 Aug 2010 6:51 PM
Phil Hunt
Thank to all. It is just something I wonder sometimes.


Show quoteHide quote
"VB 6 Devotee" <h***@yomamma.com> wrote in message
news:%23WTkXRIRLHA.5732@TK2MSFTNGP02.phx.gbl...
> Well, you could create a class with all the properties you want to save,
> then store the class in a collection or an array.
>
> Or you could try using a PropertyBag to save the data.
> http://www.a1vbcode.com/snippet.asp?ID=754
>
>
>
>
>
>
>
> "Phil Hunt" <a**@aaa.com> wrote in message
> news:eZhYFFIRLHA.2068@TK2MSFTNGP05.phx.gbl...
>> There are tons of properties and only 1 tag.
>> Is there a way to re-load a control, that would get the design time prop
>> .
>>
>> "VB 6 Devotee" <h***@yomamma.com> wrote in message
>> news:%23wnt4AIRLHA.784@TK2MSFTNGP02.phx.gbl...
>>> You might try storing the initial value in the Tag property during the
>>> Form Activate Event and then retrieve it later.
>>>
>>> "Phil Hunt" <a**@aaa.com> wrote in message
>>> news:%23KyMVaHRLHA.2068@TK2MSFTNGP05.phx.gbl...
>>>>I was hoping someone would tell me it is stored somewhere already, all I
>>>>need is to get it. Maybe not.
>>>>
>>>
>>
>>
>
Author
1 Sep 2010 12:29 PM
Dee Earley
On 25/08/2010 19:13, Phil Hunt wrote:
> There are tons of properties and only 1 tag.

Surely you dont change tons of properties per control at run time?

> Is there a way to re-load a control, that would get the design time prop .

Don't you know what you set them to? :)
VB doesn't offer a way to reset them all while the form is loaded.
You can reset a whole form by closing and recreating it.

--
Dee Earley (dee.ear***@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)