If, Elseif, Orelse Syntax in Vb. Net
I Am Having Some Confusion with Some Vb Syntax. I Have This If/Else/If/Elseif Statement I Have in Vb. It Works, but Looking Around It Seems Like This Can Be...
I am having some confusion with some VB syntax. I have this if/else/if/elseif statement I have in VB. It works, but looking around it seems like this can be cleaned up. I am new to VB coming from a C# background and I am not quite sure how to properly tweak it to clean it up. Below is my code:
If taskPath = "\" Then
taskPath = Path.GetDirectoryName(TempFilePath)
Else
If InStr(taskPath, "\\") = 1 Then
ElseIf InStr(taskPath, "\") = 1 Then
taskPath = Path.Combine(Path.GetDirectoryName(TempFilePath), Mid(taskPath, 2, Len(taskPath) - 1))
End If
End If
I would like to be able to say:
If Foo then
Bar
ElseIf Foo Then
OrElse foo then
bar
End If
Except everytime I try that type of Syntax I get errors.
I hope this makes sense, but if not, leave a comment and I will try to clarify
1 Answer
This is how the syntax should be:
If Foo then
Bar
ElseIf Foo OrElse foo then
bar
End If
With your actual code, this becomes:
If taskPath = "\" Then
taskPath = Path.GetDirectoryName(TempFilePath)
ElseIf InStr(taskPath, "\\") = 1 OrElse InStr(taskPath, "\") = 1 Then
taskPath = Path.Combine(Path.GetDirectoryName(TempFilePath), d(taskPath, 2, Len(taskPath) - 1))
End If