我对某些VB语法有些困惑。我在VB中有这个if / else / if / elseif语句。它可以工作,但环顾四周似乎可以清除。我是来自C#的VB新手,我不太确定如何正确调整它以进行清理。下面是我的代码:
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
我想说:
If Foo then
Bar
ElseIf Foo Then
OrElse foo then
bar
End If
除每次尝试这种语法外,我都会收到错误。
我希望这是有道理的,但如果没有,请发表评论,我会尽力澄清
语法应为:
If Foo then
Bar
ElseIf Foo OrElse foo then
bar
End If
使用您的实际代码,它将变成:
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