Solved

CASE Statement using the LIKE comparitive

Posted on 2001-08-03
5
169 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:jbauer22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:alaplume
ID: 6349886
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

0
 
LVL 2

Author Comment

by:jbauer22
ID: 6349895
That's an alternative but I'd really like to know if the the LIKE comparitive can be used with CASE.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 6349922
Not really but yes!!! The real advantage of a SELECT CASE is to evaluate an expression once and then compare it to a series of value. The Like operator cannot be used in this scenario.

But you can use the SELECT CASE if you really want to. You need to do a "Select Case True".

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 True

Case ScriptStart(0) Like "peg_leg*", ScriptStart(0) Like "peg_ae*", ScriptStart(0) Like "peg_flat*"
MsgBox "1- It works"

Case ScriptStart(0) Like "peg_sqr*", ScriptStart(0) Like "peg_ldg*"
MsgBox "2- It works"

Case ScriptStart(0) Like "peg_cbl*"
MsgBox "3- It works"

End Select
End Sub
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6349933
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
0
 
LVL 2

Author Comment

by:jbauer22
ID: 6349948
That's what I'm talking about.  Thanks!  A+
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question