Select Case basics!

Select Case basics!

Anonymous
Not applicable
765 Views
13 Replies
Message 1 of 14

Select Case basics!

Anonymous
Not applicable
Hello,

I'm tring to have a dabble with VBA! I'm wanting to create a form with buttons that will change various layer properties. Having a few problems with the Select Case syntax......i'd be extremely helpful if someone could point me in the right direction. (I'm currently getting the error 'Object doesn't support this property or method (Error 438)'). So I believe there's something wrong with my dimensioning?

Many thanks,

Dom

*********************************
Private Sub cmdLayerState1_Click()

Dim objLayer As AcadLayer

For Each objLayer In ThisDrawing.Layers

Select Case objLayer
Case "layer1*"
objLayer.LayerOn = False
Case "layer222"
objLayer.Plottable = False
Case "layer333"
objLayer.Freeze = True

End Select
Next
Application.Update
End Sub
***********************************
0 Likes
766 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Dom,

It should be: Select Case objLayer.Name

Joe
--

wrote in message news:4997339@discussion.autodesk.com...
Hello,

I'm tring to have a dabble with VBA! I'm wanting to create a form with
buttons that will change various layer properties. Having a few problems
with the Select Case syntax......i'd be extremely helpful if someone could
point me in the right direction. (I'm currently getting the error 'Object
doesn't support this property or method (Error 438)'). So I believe there's
something wrong with my dimensioning?

Many thanks,

Dom

*********************************
Private Sub cmdLayerState1_Click()

Dim objLayer As AcadLayer

For Each objLayer In ThisDrawing.Layers

Select Case objLayer
Case "layer1*"
objLayer.LayerOn = False
Case "layer222"
objLayer.Plottable = False
Case "layer333"
objLayer.Freeze = True

End Select
Next
Application.Update
End Sub
***********************************
0 Likes
Message 3 of 14

Anonymous
Not applicable
Hi Joe,

Many thanks for that I'm new to this VBA game.....I've just bought your book too, and it's proving to be very useful!

One other thing... I was trying to use wildcards eg "Layer1*"....but this doesn't seem to work, is it looking for an exact match?

many thanks
dom
0 Likes
Message 4 of 14

Anonymous
Not applicable
Untested:
What happens if you do something like this:

Case Like "Layer1*"

--
Matt W
"Children are like TV sets. When they start acting weird, whack them across
the head with a big rubber basketball shoe."


wrote in message news:4997412@discussion.autodesk.com...
Hi Joe,

Many thanks for that I'm new to this VBA game.....I've just bought your book
too, and it's proving to be very useful!

One other thing... I was trying to use wildcards eg "Layer1*"....but this
doesn't seem to work, is it looking for an exact match?

many thanks
dom
0 Likes
Message 5 of 14

Anonymous
Not applicable
Hi Matt,

It doesn't like it...I'm getting a compile error

cheers

dom
0 Likes
Message 6 of 14

Anonymous
Not applicable
I think I can solve in an around-about way using for example,

Case "F800" To "G"

I'd be interested to know if wild cards can be used.

Many thanks
Dom
0 Likes
Message 7 of 14

Anonymous
Not applicable
You can use this instead of Select Case (this I know works because I use it
all the time).



--
Matt W
"Children are like TV sets. When they start acting weird, whack them across
the head with a big rubber basketball shoe."


wrote in message news:4997422@discussion.autodesk.com...
I think I can solve in an around-about way using for example,

Case "F800" To "G"

I'd be interested to know if wild cards can be used.

Many thanks
Dom
0 Likes
Message 8 of 14

Anonymous
Not applicable
A little slip of the fingers I guess.


And here's the code:

[code]
Dim lays As AcadLayers
Dim lay As AcadLayer

On Error Resume Next

Set lays = ThisDrawing.Layers

For Each lay In lays
If UCase$(lay.Name) Like ("LAYER1*") Then lay.LayerOn = False
If UCase$(lay.Name) Like ("LAYER222") Then lay.Plottable = False
Next
[/code]

--
Matt W
"Children are like TV sets. When they start acting weird, whack them across
the head with a big rubber basketball shoe."


"Matt W" wrote in message
news:4997462@discussion.autodesk.com...
You can use this instead of Select Case (this I know works because I use it
all the time).



--
Matt W
"Children are like TV sets. When they start acting weird, whack them across
the head with a big rubber basketball shoe."


wrote in message news:4997422@discussion.autodesk.com...
I think I can solve in an around-about way using for example,

Case "F800" To "G"

I'd be interested to know if wild cards can be used.

Many thanks
Dom
0 Likes
Message 9 of 14

Anonymous
Not applicable
That'll do the job, Many thanks for your help

Dom
0 Likes
Message 10 of 14

Anonymous
Not applicable
You're welcome.

--
Matt W
"Children are like TV sets. When they start acting weird, whack them across
the head with a big rubber basketball shoe."


wrote in message news:4997487@discussion.autodesk.com...
That'll do the job, Many thanks for your help

Dom
0 Likes
Message 11 of 14

Anonymous
Not applicable
Here is your answer from the VBA helps files, sorry.

Note that Is and Like can't be used as comparison operators in a Select Case
statement.

Joe
--

wrote in message news:4997422@discussion.autodesk.com...
I think I can solve in an around-about way using for example,

Case "F800" To "G"

I'd be interested to know if wild cards can be used.

Many thanks
Dom
0 Likes
Message 12 of 14

Anonymous
Not applicable
Cheers for your help

Thanks

Dom
0 Likes
Message 13 of 14

Anonymous
Not applicable
Another possible issue:

In your For Each ... loop, when youy set some layers' Freeze to True, you
may want to test if the layer is ActiveLayer or not, if it is, you cannot
set its Freeze to True (you'll get runtime error). Unless you know before
hand that ActiveLayer will not possibaly included, but doing such a test is
always a good practice.

wrote in message news:4997339@discussion.autodesk.com...
Hello,

I'm tring to have a dabble with VBA! I'm wanting to create a form with
buttons that will change various layer properties. Having a few problems
with the Select Case syntax......i'd be extremely helpful if someone could
point me in the right direction. (I'm currently getting the error 'Object
doesn't support this property or method (Error 438)'). So I believe there's
something wrong with my dimensioning?

Many thanks,

Dom

*********************************
Private Sub cmdLayerState1_Click()

Dim objLayer As AcadLayer

For Each objLayer In ThisDrawing.Layers

Select Case objLayer
Case "layer1*"
objLayer.LayerOn = False
Case "layer222"
objLayer.Plottable = False
Case "layer333"
objLayer.Freeze = True

End Select
Next
Application.Update
End Sub
***********************************
0 Likes
Message 14 of 14

Anonymous
Not applicable
Thanks Norman, I'll bear that in mind.

Cheers,

Dom
0 Likes