Solved

CASE Statement using the LIKE comparitive

Posted on 2001-08-03
5
168 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

810 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