473,563 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 28708
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****@discuss ions.microsoft. com> wrote in message
news:0E******** *************** ***********@mic rosoft.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.EndsWit h("ing") Then
....
ElseIf myValue.EndsWit h("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.EndsWit h("ing") Then
....
ElseIf myValue.EndsWit h("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****@discuss ions.microsoft. com> wrote in message
news:2E******** *************** ***********@mic rosoft.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.EndsWit h("ing") Then
....
ElseIf myValue.EndsWit h("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.Frida y 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*******@hotm ail.com> wrote in message
news:11******** *************@v 46g2000cwv.goog legroups.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.Frida y 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
14615
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 allow entry to one or the other or Both at the same time. Now I tried to use an If ElseIf but it got too hard to track, so now I am using a...
9
3620
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 doing wrong? Thanks
10
2153
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
9319
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
3765
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 a word or a number, ie... Low or 1 Medium or 2 High or 3
8
4713
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", "krbtgt", "quality7" ' don't show
16
19029
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 1"); break;
5
10111
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
21652
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 "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan" case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb" End Select
0
7664
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.