473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Select case wildcard

Hi

Is it possible to compare a vaule for a select case statement using a
wildcard.

e.g. somthing like

Select case myValue
case like "*ing"
end select

would evaluate as true for "singing", "raining", etc.

If it is possible what is the corerct sysntax (obviously I used the one
above and it didn't work).

Regards

Michael Bond
Mar 17 '06 #1
6 28675
CMM
If myValue Like "*ing" Then
....
ElseIf myValue Like "*bla" Then
....
End If

"Like" is a little known and handy VB Operator.

--
-C. Moya
www.cmoya.com
"mabond" <ma****@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
Hi

Is it possible to compare a vaule for a select case statement using a
wildcard.

e.g. somthing like

Select case myValue
case like "*ing"
end select

would evaluate as true for "singing", "raining", etc.

If it is possible what is the corerct sysntax (obviously I used the one
above and it didn't work).

Regards

Michael Bond

Mar 17 '06 #2
> If myValue Like "*ing" Then
...
ElseIf myValue Like "*bla" Then
...
End If


For this particular pattern, using String.EndsWith method would be faster:
If myValue.EndsWith("ing") Then
....
ElseIf myValue.EndsWith("bla") Then
....
End If

Of course, you cannot use it with more complicated patterns.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Mar 17 '06 #3
Sorry Guys

I know how to use the wildcard in an "if" loop. My question was about
whether, or not, it could be used in a Select Case statment

Regards

Michael Bond

"Peter Macej" wrote:
If myValue Like "*ing" Then
...
ElseIf myValue Like "*bla" Then
...
End If


For this particular pattern, using String.EndsWith method would be faster:
If myValue.EndsWith("ing") Then
....
ElseIf myValue.EndsWith("bla") Then
....
End If

Of course, you cannot use it with more complicated patterns.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code

Mar 20 '06 #4
CMM
> I know how to use the wildcard in an "if" loop. My question was about
whether, or not, it could be used in a Select Case statment
You mean "if" block. Not loop. ;-)
I don't think VB has ever supported Like in Select Case comparisons. A
little interesting considering you could do so many other things with Select
Case (like alphabetical comparisons using "To" etc). But, I'd be surprised
if MS changed this behavior in the latest versions of VB. It's Tradition I
guess.

From VB.Classic documentation: Note that Is and Like can't be used as
comparison operators in a Select Case statement.

--
-C. Moya
www.cmoya.com
"mabond" <ma****@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com... Sorry Guys

I know how to use the wildcard in an "if" loop. My question was about
whether, or not, it could be used in a Select Case statment

Regards

Michael Bond

"Peter Macej" wrote:
> If myValue Like "*ing" Then
> ...
> ElseIf myValue Like "*bla" Then
> ...
> End If


For this particular pattern, using String.EndsWith method would be
faster:
If myValue.EndsWith("ing") Then
....
ElseIf myValue.EndsWith("bla") Then
....
End If

Of course, you cannot use it with more complicated patterns.

--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code

Mar 20 '06 #5

mabond wrote:
Sorry Guys

I know how to use the wildcard in an "if" loop. My question was about
whether, or not, it could be used in a Select Case statment


Dim s1 As String = "abc"
Dim s2 As String = "ef"

Select Case True
Case s1 Like "a*c"
'...
Case s2.EndsWith("f")
'....
Case s1 & s2 = "abcef"
'...
Case Today.DayOfWeek = DayOfWeek.Friday And Today.Day = 13
'...
Case Else
'...
End Select

Note C# can't do this in a switch statement :) (yes I know if else if
is equivalent...)

--
Larry Lard
Replies to group please

Mar 20 '06 #6
CMM
Very Nice.
(Personally, I think If/ElseIf is more intuitive though.)

--
-C. Moya
www.cmoya.com
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...

mabond wrote:
Sorry Guys

I know how to use the wildcard in an "if" loop. My question was about
whether, or not, it could be used in a Select Case statment


Dim s1 As String = "abc"
Dim s2 As String = "ef"

Select Case True
Case s1 Like "a*c"
'...
Case s2.EndsWith("f")
'....
Case s1 & s2 = "abcef"
'...
Case Today.DayOfWeek = DayOfWeek.Friday And Today.Day = 13
'...
Case Else
'...
End Select

Note C# can't do this in a switch statement :) (yes I know if else if
is equivalent...)

--
Larry Lard
Replies to group please

Mar 20 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
10
by: MLH | last post by:
Suppose the following... Dim A as Date A=#7/24/2005# I wish to compare value of A against 2 other values: 1) 8/1/2005 2) 9/1/2005 Which is better and why... First:
7
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
3
by: Rob Meade | last post by:
Ok - I *think* this is only different in .net 2.0 - as I've not had any problems in the past, but then maybe I've not tried it... I have a value being read from an xml file where the value maybe...
8
by: | last post by:
Hello, This is gonna sound real daft, but how do I test a Select Case statement for variants of a theme? Here's a snippet of my code... Select Case sUsr Case "Guest", "TsInternetUser",...
16
by: ME | last post by:
In C# the following code generates a compiler error ("A constant value is expected"): public void Test(string value) { switch (value) { case SimpleEnum.One.ToString(): MessageBox.Show("Test...
5
by: PJ6 | last post by:
Select Case o.GetType Case = GetType(SomeRandomTypeName) '... End Select Why doesn't this work? Can I make it work or am I stuck with ElseIf for a long list? Paul
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.