473,498 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select Case and OrElse

kd
Hi All,

Does 'Select Case' construct perform logical short-circuiting like the
'OrElse' opeartor or does it function like the 'Or' operator?

For Example:
Dim sTeststr as String
sTeststr = "ABC"
Select Case sTeststr
Case "ABC","DEF","GHI"
....
....
End Select

Is sTeststr compared to all the values in the case, irrespective of whether
or not the value is found before scanning through all the case values?

kd

Nov 21 '05 #1
12 5535
KD

The OrElse works like the OR in any other language than VB

It stops after that the first evaluation is true

I hope this helps?

Cor
Nov 21 '05 #2
kd wrote:
Hi All,

Does 'Select Case' construct perform logical short-circuiting like the
'OrElse' opeartor or does it function like the 'Or' operator?

For Example:
Dim sTeststr as String
sTeststr = "ABC"
Select Case sTeststr
Case "ABC","DEF","GHI"
...
...
End Select

Is sTeststr compared to all the values in the case, irrespective of
whether or not the value is found before scanning through all the
case values?


Why not find out yourself?

Dim sTeststr as String
sTeststr = "ABC"
Select Case sTeststr
Case "ABC"
MsgBox("compared to ABC")
Case "DEF"
MsgBox("compared to DEF")
End Select

--

Riki
Nov 21 '05 #3
kd
Thanks Cor for your reply.

I think, I have not framed the question right. Let me give it a try again.

When a Case block, has several values, is the Case variable compared to all
the values, even if a match is found (before completing the entire list of
Case values)? In other words, does it function like the Or Operator in
vb.net, or is the scanning aborted if a match is found, (before scanning the
entire list) like the OrElse Opeartor?

kd

"Cor Ligthert" wrote:
KD

The OrElse works like the OR in any other language than VB

It stops after that the first evaluation is true

I hope this helps?

Cor

Nov 21 '05 #4
KD,

Abort it falls down until found.

Cor
Nov 21 '05 #5
kd
Cor,

I hope I got you right.

So, you mean to say that in the following example,
For Example:
Dim sTeststr as String
sTeststr = "ABC"
Select Case sTeststr
Case "ABC","DEF","GHI"
....
....
End Select
since sTeststr is matched for the first case value, sTeststr is not compared
with "DEF" or "GHI"?

kd.

"Cor Ligthert" wrote:
KD,

Abort it falls down until found.

Cor

Nov 21 '05 #6
kd schrieb:
Does 'Select Case' construct perform logical short-circuiting like the
'OrElse' opeartor or does it function like the 'Or' operator?
Yes, the function of 'Select Case' is similar to 'OrElse'. The
expression is compared to the list of values, until the first match
occurs.
For Example:
Dim sTeststr as String
sTeststr = "ABC"
Select Case sTeststr
Case "ABC","DEF","GHI"
...
...
End Select


In your example 'Select Case' stops comparing at "ABC". The other
values are ignored.

Thorsten Doerfler
Nov 21 '05 #7
KD,

You are speeding up nanoseconds.

When you really wants to know you can see this what happens in the
disassembly window from the debugger, (Debug -> Windows -> Disassembly) that
shows you complete the process.

I hope this helps?

Cor
Nov 21 '05 #8
kd
Thanks Cor for your reply.

I think, I have not framed the question right. Let me give it a try again.

When a Case block, has several values, is the Case variable compared to all
the values, even if a match is found (before completing the entire list of
Case values)? In other words, does it function like the Or Operator in
vb.net, or is the scanning aborted if a match is found, (before scanning the
entire list) like the OrElse Opeartor?

kd

"Cor Ligthert" wrote:
KD

The OrElse works like the OR in any other language than VB

It stops after that the first evaluation is true

I hope this helps?

Cor

Nov 21 '05 #9
KD,

Abort it falls down until found.

Cor
Nov 21 '05 #10
kd
Cor,

I hope I got you right.

So, you mean to say that in the following example,
For Example:
Dim sTeststr as String
sTeststr = "ABC"
Select Case sTeststr
Case "ABC","DEF","GHI"
....
....
End Select
since sTeststr is matched for the first case value, sTeststr is not compared
with "DEF" or "GHI"?

kd.

"Cor Ligthert" wrote:
KD,

Abort it falls down until found.

Cor

Nov 21 '05 #11
kd schrieb:
Does 'Select Case' construct perform logical short-circuiting like the
'OrElse' opeartor or does it function like the 'Or' operator?
Yes, the function of 'Select Case' is similar to 'OrElse'. The
expression is compared to the list of values, until the first match
occurs.
For Example:
Dim sTeststr as String
sTeststr = "ABC"
Select Case sTeststr
Case "ABC","DEF","GHI"
...
...
End Select


In your example 'Select Case' stops comparing at "ABC". The other
values are ignored.

Thorsten Doerfler
Nov 21 '05 #12
KD,

You are speeding up nanoseconds.

When you really wants to know you can see this what happens in the
disassembly window from the debugger, (Debug -> Windows -> Disassembly) that
shows you complete the process.

I hope this helps?

Cor
Nov 21 '05 #13

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

Similar topics

6
10876
by: Dianna | last post by:
I don't understand why the dataview or the dataset does not have a 'Select Distinct' option. They both can do so much to filter the data except that. The article Microsoft has 326176 works, but not...
14
2537
by: Jeremy | last post by:
Paul Vick posted this Blog (link below), "The Ballad of AndAlso and OrElse", and I noticed people were discussing this topic semi-regularly so I thought I would post the pseudo-official word of...
10
4613
by: Mike Hale | last post by:
Is it better to use AndAlso and OrElse by default rather than the regual And & Or? MikeH
16
1764
by: Raterus | last post by:
I kinda just stumbled across these operators, they seem great, as you can forget the second expression depending on the result of the first, but are there any cons to using these? From my...
8
4695
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",...
9
10358
by: Lior | last post by:
Hello . I know that the AndAlso and OrElse statements are short-circuiting And and Or statements , respectively . Should I always use (I don't like the word "always" ...) AndAlso instead of...
15
3483
by: Benny Raymond | last post by:
I'm confused as to how fallthrough is limited in switch. For example the following works: string switch_test = "a"; switch (switch_test) { case "a": case "b": case "c": doSomething(a);
3
19215
by: Siegfried Heintze | last post by:
Are there operators in C# that are the counterparts of "OrElse" and "AndAlso" that I can use when translating the following program from VB.NET to C#? Thanks, Siegfried Namespace vbtest...
8
1244
by: Euvin | last post by:
I am kind of confuse as to how these operators work: AndAlso and OrElse Anyone care to explain. Some examples would be great!
0
7168
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,...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4916
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...
0
4595
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...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
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 ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.