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.
Printable View
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.
I dont know if you can do it in VB.NET but it can be done in C#.
This might work in VB.NETCode:if(data == "a" || data == "b" || data == "c")
{
//do statements
}
VB Code:
If(data = "a" Or data = "b" Or data = "c") 'do statements EndIf
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.
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.
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
so orElse is faster than or? Oh yeah..that s right. It stop's processing the moment it matches one right?
Yes, OrElse and AndAlso meant to be faster esp if you put the one that most probably meets the criteria first.
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
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! :D