Link to home
Start Free TrialLog in
Avatar of jbauer22
jbauer22

asked on

CASE Statement using the LIKE comparitive

I have a value stored in the first element of an array: ScriptStart(0).  I want to select the case based on if the first element's string is "LIKE" one of the Cases.  I don't know the proper syntax to accomplish this.  Here's what I'm trying (with no luck):

Sub CaseLike()
'--- As you can see below there is no CASE for "peg_sqr2"
'--- but there is a CASE for "peg_sqr"
'--- so I need help with a LIKE statement
Dim ScriptStart(5)
ScriptStart(0) = "peg_sqr2"

Select Case ScriptStart(0)

Case Like "peg_leg*", "peg_ae*", "peg_flat*"
MsgBox "It works"

Case Like "peg_sqr*", "peg_ldg*"
MsgBox "It works"

Case Like "peg_cbl*"
MsgBox "It works"

End Select
End Sub
Avatar of alaplume
alaplume

Thy something like this instead:

if instr(1,ScriptStart(0),"peg_leg")>0 _or
   instr(1,ScriptStart(0),"peg_ae")>0 _or
   instr(1,ScriptStart(0),"peg_flat")>0 then

   msgbox "It Works"

elseif ...
.
.
.
end if

Avatar of jbauer22

ASKER

That's an alternative but I'd really like to know if the the LIKE comparitive can be used with CASE.
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Best you will be able to do in this case will be ...

Select Case Left(ScriptStart(0), 7)

Case "peg_leg", "peg_cbl", "peg_sqr", "peg_ldg"
   MsgBox "It works"
Case Else
   Select Case Left(ScriptStart(0), 6)
      Case "peg_ae",
         Msgbox "6 Works"
      Case Else
          Select Case Left(ScriptStart(0), 8)
               Case "peg_flat"
                    MsgBox "8 works"
               Case Else
                    msgbox "Not Found
          End Select
    End Select
End Select
That's what I'm talking about.  Thanks!  A+