Solved

Select Case combined with like operator

Posted on 2003-12-09
9
852 Views
Last Modified: 2010-05-01
Hi,

I can't find a way to do what i'm after.

I need a select case function that will allow for the like operator.

eg..

case like "*ABC"
     blahblah
case like "*123*"
    blahblah2

I need to match the patern of the case to wildcard entries - but all I can find is that the like operator with wildcards won't work within a select case.

Any ideas anyone?

Thanks,

Benjamin.
0
Comment
Question by:benspan
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:mccainz2
ID: 9909202
why not use an if - elseif structure ...

if case like "*abc"
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9909207
Argghhh, hit enter on my touchoad ..

why not use an if - elseif structure ...

if case like "*abc"
.....
else if case like "*whatever"
.. etc
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9909214
Hi benspan,
I suggest you have a look at regular expressions.

Search for regex here on EE, or have a look at this question

http://oldlook.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20528014.html

The last answer has a link to Microsoft with even more information.

Learning Regular Expressions is not simple, but once you get the gist of it, you will see that it can solve not just this particular problem you are having, but many more, to the point that it may become addictive!


Dabas
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Expert Comment

by:lttia1
ID: 9909250
you can also make use of this if using if-else statement:

If InStr(Text1.Text, "ABC") <> 0 Then
   blahblah
ElseIf InStr(Text1.Text, "123") <> 0 Then
    blahblah
End if
0
 

Author Comment

by:benspan
ID: 9909586
I'm trying to avoid a massive if then listing, so was trying to use the select case calls.

The instr is pretty much the like statement with wildcard values by the looks.

What i'm really trying to find out is if it is possible to use the select case statement to do fancy comparisons...

select case something

     case something like "*ABC*"
           x
     case something like "*BCD*"
           y

etc etc

the following format works:
select case something
    case is = "A"
          x
    case is = "B"
          y
etc etc, but this will only match exact values - whereas i want to match values with wildcards.

looks as though the case statement just can't handle this?
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9909671
benspan,
> looks as though the case statement just can't handle this?
Right.
The case statement cannot handle this.
Regex is the way to go!

Dabas
0
 
LVL 39

Expert Comment

by:appari
ID: 9910308
can try something like this

Private Sub Command1_Click()
Dim x As String

x = InputBox("Enter Name")
Select Case True
Case x Like "*Appari"
    MsgBox "has Appari"
Case x Like "*Dabas"
    MsgBox "has Dabas"

End Select
End Sub
0
 
LVL 39

Accepted Solution

by:
appari earned 50 total points
ID: 9910311
missed ending *

can try something like this

Private Sub Command1_Click()
Dim x As String

x = InputBox("Enter Name")
Select Case True
Case x Like "*Appari*"
    MsgBox "has Appari"
Case x Like "*Dabas*"
    MsgBox "has Dabas"

End Select
End Sub
0
 

Author Comment

by:benspan
ID: 9917009
Perfect - exactly what i am trying to do.

you're definitely a guru.

Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA open file from excel cell 4 44
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 56
RUNRMTCMD from AS/400 12 69
Collapse and expand table in Word 2010 2 36
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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