Hi.

This seems like it would be easy...

How do I code the follow as a select case?

If TypeOf ctlBulk Is ComboBox Or _
TypeOf ctlBulk Is OptionButton Or _
TypeOf ctlBulk Is Label Then
ctlBulk.Enabled = False
ctlBulk.Text = ""
ctlBulk.Value = False
end if

Select Case TypeOf ctlBulk.....is not working
Case ComboBox
Case OptionButton
etc..
Thanks.

Re: Select Case using TypeOf by Jeff

Jeff
Thu Aug 24 12:58:20 CDT 2006

"dman" <unlisted@aol.com> wrote in message
news:e92%23$X6xGHA.4204@TK2MSFTNGP04.phx.gbl...

> How do I code the follow as a select case?

You don't. TypeOf is an odd beast. Perhaps TypeName() will serve you better.



Re: Select Case using TypeOf by Rick

Rick
Thu Aug 24 12:59:09 CDT 2006

> This seems like it would be easy...
>
> How do I code the follow as a select case?
>
> If TypeOf ctlBulk Is ComboBox Or _
> TypeOf ctlBulk Is OptionButton Or _
> TypeOf ctlBulk Is Label Then
> ctlBulk.Enabled = False
> ctlBulk.Text = ""
> ctlBulk.Value = False
> end if
>
> Select Case TypeOf ctlBulk.....is not working
> Case ComboBox
> Case OptionButton
> etc..
> Thanks.

I believe TypeOf is only available in If-Then statements; try using
TypeName..

Select Case TypeName(ctlBulk)
Case "ComboBox"
Case "OptionButton"
etc.

Note the quote marks around the control types in the Case statements.

Rick



Re: Select Case using TypeOf by Ken

Ken
Thu Aug 24 13:00:00 CDT 2006

"dman" <unlisted@aol.com> wrote in message
news:e92%23$X6xGHA.4204@TK2MSFTNGP04.phx.gbl...
> Hi.
>
> This seems like it would be easy...
>
> How do I code the follow as a select case?
>
> If TypeOf ctlBulk Is ComboBox Or _
> TypeOf ctlBulk Is OptionButton Or _
> TypeOf ctlBulk Is Label Then
> ctlBulk.Enabled = False
> ctlBulk.Text = ""
> ctlBulk.Value = False
> end if
>
> Select Case TypeOf ctlBulk.....is not working
> Case ComboBox
> Case OptionButton
> etc..
> Thanks.

You can either...

Select Case True 'some people hate this
Case TypeOf ctlBulk Is OptionButton, TypeOf ctlBulk Is Label ' etc

or....

Select Case TypeName(ctlBulk)
Case "OptionButton", "Label" 'etc

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
In Loving Memory - http://www.vbsight.com/Remembrance.htm



Re: Select Case using TypeOf by Rick

Rick
Thu Aug 24 13:19:52 CDT 2006

> You can either...
>
> Select Case True 'some people hate this

Yep! Some people sure do. <g>

Rick



Re: Select Case using TypeOf by dman

dman
Thu Aug 24 13:21:49 CDT 2006

Thanks guys!

The only reason I'm doing this is because when I disable my frame,
none of the controls on the frame become disabled.

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:eFibmd6xGHA.3568@TK2MSFTNGP03.phx.gbl...
> "dman" <unlisted@aol.com> wrote in message
> news:e92%23$X6xGHA.4204@TK2MSFTNGP04.phx.gbl...
>> Hi.
>>
>> This seems like it would be easy...
>>
>> How do I code the follow as a select case?
>>
>> If TypeOf ctlBulk Is ComboBox Or _
>> TypeOf ctlBulk Is OptionButton Or _
>> TypeOf ctlBulk Is Label Then
>> ctlBulk.Enabled = False
>> ctlBulk.Text = ""
>> ctlBulk.Value = False
>> end if
>>
>> Select Case TypeOf ctlBulk.....is not working
>> Case ComboBox
>> Case OptionButton
>> etc..
>> Thanks.
>
> You can either...
>
> Select Case True 'some people hate this
> Case TypeOf ctlBulk Is OptionButton, TypeOf ctlBulk Is Label ' etc
>
> or....
>
> Select Case TypeName(ctlBulk)
> Case "OptionButton", "Label" 'etc
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
> In Loving Memory - http://www.vbsight.com/Remembrance.htm
>



Re: Select Case using TypeOf by Rick

Rick
Thu Aug 24 13:45:49 CDT 2006

> The only reason I'm doing this is because when I disable my frame,
> none of the controls on the frame become disabled.

That would be because the control are not IN the frame, rather they are
simply on TOP of the Frame. You can test that out by moving the Frame
control... if the controls don't move with it, the controls are not in the
frame. To put a control into a container object (Frame, PictureBox, etc.),
there are two ways. When first placing them... click only once on the
control to highlight it in the ToolBox, then move the mouse to the container
object, depress the left-mouse button and drag. That draws the control into
the container object. If you choose to double-click on the control in the
ToolBox, that places the control directly on the form (with a ZOrder higher
than the other controls at the graphic level). To get it into the container
object from here, select the control on the form, hit Ctrl+X to cut it from
the form, select the container object and then hit Ctrl+V to paste it into
the container object. Once you have objects IN a container object, disabling
the container object will disable any controls that are IN it.

Rick



Re: Select Case using TypeOf by dman

dman
Thu Aug 24 14:08:06 CDT 2006

Thanks, I will give that a try.

After thinking about why I was doing the select case,
I thought I would mentioned it, incase I could do just what you said.



"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:%23WmwF26xGHA.1788@TK2MSFTNGP05.phx.gbl...
>> The only reason I'm doing this is because when I disable my frame,
>> none of the controls on the frame become disabled.
>
> That would be because the control are not IN the frame, rather they are
> simply on TOP of the Frame. You can test that out by moving the Frame
> control... if the controls don't move with it, the controls are not in the
> frame. To put a control into a container object (Frame, PictureBox, etc.),
> there are two ways. When first placing them... click only once on the
> control to highlight it in the ToolBox, then move the mouse to the
> container object, depress the left-mouse button and drag. That draws the
> control into the container object. If you choose to double-click on the
> control in the ToolBox, that places the control directly on the form (with
> a ZOrder higher than the other controls at the graphic level). To get it
> into the container object from here, select the control on the form, hit
> Ctrl+X to cut it from the form, select the container object and then hit
> Ctrl+V to paste it into the container object. Once you have objects IN a
> container object, disabling the container object will disable any controls
> that are IN it.
>
> Rick
>



Re: Select Case using TypeOf by dman

dman
Thu Aug 24 14:14:04 CDT 2006

Neither method is working for me...perhaps it doesn't work with VB6 SP3.


"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:%23WmwF26xGHA.1788@TK2MSFTNGP05.phx.gbl...
>> The only reason I'm doing this is because when I disable my frame,
>> none of the controls on the frame become disabled.
>
> That would be because the control are not IN the frame, rather they are
> simply on TOP of the Frame. You can test that out by moving the Frame
> control... if the controls don't move with it, the controls are not in the
> frame. To put a control into a container object (Frame, PictureBox, etc.),
> there are two ways. When first placing them... click only once on the
> control to highlight it in the ToolBox, then move the mouse to the
> container object, depress the left-mouse button and drag. That draws the
> control into the container object. If you choose to double-click on the
> control in the ToolBox, that places the control directly on the form (with
> a ZOrder higher than the other controls at the graphic level). To get it
> into the container object from here, select the control on the form, hit
> Ctrl+X to cut it from the form, select the container object and then hit
> Ctrl+V to paste it into the container object. Once you have objects IN a
> container object, disabling the container object will disable any controls
> that are IN it.
>
> Rick
>



Re: Select Case using TypeOf by Rick

Rick
Thu Aug 24 14:16:46 CDT 2006

> After thinking about why I was doing the select case,
> I thought I would mentioned it, incase I could do just what you said.

It never hurts to give additional (related) information (most welcomed with
the initial posting); it gives us a more complete picture from which to
fashion an answer. Very often, the person asking the question is, like I
think you may have, asking the wrong question. Either from a lack of
experience or simply a "blind spot", they end up focusing on the wrong
"potential solution" and end up framing their question around that.

Rick



Re: Select Case using TypeOf by Rick

Rick
Thu Aug 24 14:19:26 CDT 2006

> Neither method is working for me...perhaps it doesn't work with VB6 SP3.

It should work. I use VB6 SP5 now, but for the longest time I used SP3 and
have used both procedures successfully with either.

When you move your frame, do any controls move with it? When you say it
isn't working for you, exactly what IS happening when you try each procedure
I outlined?

Rick



Re: Select Case using TypeOf by Bob

Bob
Thu Aug 24 14:43:13 CDT 2006

"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:Oedoln6xGHA.356@TK2MSFTNGP02.phx.gbl
>> You can either...
>>
>> Select Case True 'some people hate this
>
> Yep! Some people sure do. <g>

I think I resemble that remark!

--
Reply to the group so all can participate
VB.Net: "Fool me once..."


Re: Select Case using TypeOf by dman

dman
Thu Aug 24 14:47:59 CDT 2006

What I would like to have happen is when I disable the frame, the controls
in the frame change to the 'disabled' color - same as the frame, or same as
doing
.enabled = false for each control.

When I move the frame, the controls move with it.
When I disable the frame, although I can't access the controls in the frame,
they remain the same 'enabled' color giving the user the impression they can
enter data into them.

I have tried the click once in toolbox, left click and drag in the frame as
well as using
ctrl-x with ctrl-v to add a control into the frame.

Please advise, Thanks!

"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in
message news:O%23$I4I7xGHA.1788@TK2MSFTNGP05.phx.gbl...
>> Neither method is working for me...perhaps it doesn't work with VB6 SP3.
>
> It should work. I use VB6 SP5 now, but for the longest time I used SP3 and
> have used both procedures successfully with either.
>
> When you move your frame, do any controls move with it? When you say it
> isn't working for you, exactly what IS happening when you try each
> procedure I outlined?
>
> Rick
>



Re: Select Case using TypeOf by Rick

Rick
Thu Aug 24 15:34:14 CDT 2006

> What I would like to have happen is when I disable the frame, the controls
> in the frame change to the 'disabled' color - same as the frame, or same
> as doing
> .enabled = false for each control.

Ahh! I see what you are after now... you want the all the controls to look
disabled. The method you post initially (where you iterate through the
controls and disable the appropriate ones) is the way to go on this.

Rick



Re: Select Case using TypeOf by Mike

Mike
Thu Aug 24 17:10:15 CDT 2006

Hi Jeff,

> You don't. TypeOf is an odd beast. Perhaps TypeName() will serve you better.

I'm curious as to how it's an "odd beast", I don't recall ever having any problems with it is there some issue I'm
unaware with it or just because it requires an "Is" which doesn't lend itself well to Select Case statements?
Personally I would recommend TypeOf over TypeName() both for performance and maintenance reasons, it avoids string
operations and I would assume is pretty much just a direct COM QueryInterface() call so it should be nice and fast too.
Cheers,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/



Re: Select Case using TypeOf by Ken

Ken
Thu Aug 24 17:27:44 CDT 2006

"Mike D Sutton" <EDais@mvps.org> wrote in message
news:OdYfVo8xGHA.3440@TK2MSFTNGP06.phx.gbl...
> Hi Jeff,
>
>> You don't. TypeOf is an odd beast. Perhaps TypeName() will serve you
>> better.
>
> I'm curious as to how it's an "odd beast", I don't recall ever having any
> problems with it is there some issue I'm unaware with it or just because
> it requires an "Is" which doesn't lend itself well to Select Case
> statements? Personally I would recommend TypeOf over TypeName() both for
> performance and maintenance reasons, it avoids string operations and I
> would assume is pretty much just a direct COM QueryInterface() call so it
> should be nice and fast too.
> Cheers,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: Http://EDais.mvps.org/

imo, there's a time and place for both. TypeOf, since it requires 'Is' to
work, essentially returns only booleans.

TypeOf is much faster because the compiler "knows" ahead of time what you're
looking for. But that can bite you if you have a "favorite routine" that
includes tests for 3rd party components or ActiveX controls that don't exist
in the current project. TypeOf will bomb if the control type doesn't exist
in the current project.... which means you'll have several versions of that
"favorite routine" laying around.

TypeName is more generic. Yeah, it's slower but... we're not talking .Net
slower or anything ;-)

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
In Loving Memory - http://www.vbsight.com/Remembrance.htm



Re: Select Case using TypeOf by MikeD

MikeD
Thu Aug 24 18:40:47 CDT 2006


"dman" <unlisted@aol.com> wrote in message
news:ebm6HZ7xGHA.3452@TK2MSFTNGP04.phx.gbl...
> What I would like to have happen is when I disable the frame, the controls
> in the frame change to the 'disabled' color - same as the frame, or same
> as doing
> .enabled = false for each control.

Usually, it's the opposite that gets asked: "how do I disable controls
without making them looked disabled (IOW, grayed)". <g>

--
Mike
Microsoft MVP Visual Basic



Re: Select Case using TypeOf by Larry

Larry
Thu Aug 24 19:54:35 CDT 2006


"dman" <unlisted@aol.com> wrote
> What I would like to have happen is when I disable the frame, the controls
> in the frame change to the 'disabled' color - same as the frame, or same as
> doing .enabled = false for each control.

> Please advise, Thanks!

If you do a significant amount of managing the Enabled properties of a
number of controls, you might consider using a routine like the one below.
You can pass in a single control, or an array of controls, or some
combination thereof to set all of their Enabled properties:

HTH
LFS

Private Sub Command1_Click()
Dim OptionGroup
OptionGroup = Array(Text1, Text2, Check1, Check1)

' Some usage examples.....
' A single control
SetEnabled True, Text1

' A group of controls
SetEnabled True, Check1, Check2, Text1, Text2
SetEnabled False, Array(Text1, Text2, Check1, Check2)

' A stored grouping
SetEnabled False, OptionGroup

' A mixed bag
SetEnabled True, Text1, OptionGroup, Check1

End Sub


Private Sub SetEnabled(ByVal Value, ParamArray Group())
Dim item, subitem

For Each item In Group

If TypeOf item Is Control Then
item.Enabled = Value

ElseIf IsArray(item) Then
For Each subitem In item

If TypeOf subitem Is Control Then
subitem.Enabled = Value

ElseIf IsArray(subitem) Then
SetEnabled Value, subitem

End If
Next

End If
Next

End Sub




Re: Select Case using TypeOf by Randy

Randy
Fri Aug 25 18:46:08 CDT 2006

> TypeName is more generic. Yeah, it's slower but... we're not
> talking .Net slower or anything ;-)


<g>

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.