Case Statement

S

sacredarms

Is it possible to use wild cards in case statements and if so how?

Any information greatly appreciated.
Thanks
 
K

Ken Snell [MVP]

From what I posted in a soon-to-be-obsolete newsgroup to this multiposted
question:
-----------------
The Case portion of the Select Case cannot use wildcards directly, but you
might be able to work around this if you can craft a
comparison statement and use its value of true or false as the selection.
For example,


Select Case (MyVariableName Like "*10280"
Case True
' do things here if the match is valid
Case False
' do things here if the match is invalide
End Select


Another way to approach this is to use different match comparisons as the
Case statements:


Select Case True
Case (MyVariableName Like "*10280")
' do things here if the match is valid
Case (MyVariableName Like "*99999")
' do things here if the match is valid
End Select
 
D

david epsom dot com dot au

BASIC case statements are not just jump labels like
they are in some languages: instead, every line is
interpreted as it runs, giving you enormous flexibility:


select case True
case j$ like "[abcd][1234]"
...
case j$ like "fred*"
...
case 0 <> instr("a",j$)
...
case len(j$) > 5
...
case eval(j$ & " In " & "('x','y','z')")
...
case else
select case j$
case "1"
...
case str(MyFunc(j$) or MyArray(val(j$)))
...
case eval(j$)
...
end select
end select


(david)
 
M

Michael D. Ober

Ken Snell said:
From what I posted in a soon-to-be-obsolete newsgroup to this multiposted
question:

Just because MS has dropped VB6 support doesn't mean that the VB 6
newsgroups will be obsolete. There are still a lot of VB 6 programmers out
there. If anything, these NGs will become more important.

Now to the case statement question:

In situatations like this, I use

if cond1 then
....

elseif cond2 then
...

..
..
else
...
end if

Also, you can use the Like statement in the case statements

select case SomeValue
case like "*ABC"

end select


Mike Ober.
 
K

Ken Snell [MVP]

Michael D. Ober said:
Just because MS has dropped VB6 support doesn't mean that the VB 6
newsgroups will be obsolete. There are still a lot of VB 6 programmers
out
there. If anything, these NGs will become more important.

My comment was not about a VB6 newsgroup... it has to do with one of the
Access newsgroups that is being dropped because a new ng for that topic in
Access is replacing it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top