|
-
May 1st, 2003, 09:23 AM
#1
Shorter syntax for if statement
was wondering if there was a shortcut for doing a multi Or if statement
like
if data = "a" or data="b" or data ="c".
I could use a select case then do case a,b,c..etc..
but wanted to know if there was something else first.
-
May 1st, 2003, 09:37 AM
#2
Frenzied Member
I dont know if you can do it in VB.NET but it can be done in C#.
Code:
if(data == "a" || data == "b" || data == "c")
{
//do statements
}
This might work in VB.NET
VB Code:
If(data = "a" Or data = "b" Or data = "c")
'do statements
EndIf
Dont gain the world and lose your soul
-
May 1st, 2003, 09:46 AM
#3
No. I meant i know i can do that. Thats not the problem. Its just that there are alot more of them, so I was trying to see if there was something shorter.
-
May 1st, 2003, 09:49 AM
#4
you know like when setting values in an array you can use that {"a","b,"c"} thing when setting the array. Just wondered if there was something similar to that for checking the value of a variable. Like I said. I can use Select Case, but just looking for other options if they exist.
-
May 1st, 2003, 09:50 AM
#5
Frenzied Member
I am not aware of a way to shorten the code. but you can shorten the proccess time by:
VB Code:
If data="a" OrElse data="b" OrElse data="C" Then
'something
End If
Last edited by Lunatic3; May 1st, 2003 at 09:58 AM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 1st, 2003, 09:54 AM
#6
so orElse is faster than or? Oh yeah..that s right. It stop's processing the moment it matches one right?
-
May 1st, 2003, 09:56 AM
#7
Frenzied Member
Yes, OrElse and AndAlso meant to be faster esp if you put the one that most probably meets the criteria first.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 1st, 2003, 10:06 AM
#8
It depends where you want to save space or time or how things are laid out but this MAY be shorter:
VB Code:
Dim data = "a"
Dim choice As String = "abc"
If choice.IndexOf(Data) > -1 Then
MsgBox(Data)
End If
-
May 1st, 2003, 12:00 PM
#9
Well peformance is all that really matters and in comparisson to Or, orlese is a noticable improvement. And currently with my re-write of an old Unix mainframe application into .NET, it is taking 7 seconds to perform what used to take at least 5 minutes.
So its all good!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|