I am trying to find out why OrElse doesn't work in my code which is a snippet of code I put together to test the OrElse.
If I take the following code:
Module Module1
Sub Main()
Dim str As String = String.Empty
Dim j As Integer
Dim k As Integer
str = "aaa"
j = 5
k = 0
If str = String.Empty Or (j / k) Then
Console.WriteLine("Inside If statement")
Else
Console.WriteLine("Inside Else Statement")
End If
Console.ReadLine()
End Sub
End Module
I get a divide by zero error (which was expected). But if I change the Or to OrElse, I don't get the error which I figured I would.
Module Module1
Sub Main()
Dim str As String = String.Empty
Dim j As Integer
Dim k As Integer
str = "aaa"
j = 5
k = 0
If str = String.Empty OrElse (j / k) Then
Console.WriteLine("Inside If statement")
Else
Console.WriteLine("Inside Else Statement")
End If
Console.ReadLine()
End Sub
End Module
Since "str = String.Empty" is false, the next test should go to "(j / k)" which should get an error (as it did before), but prints the "Inside If statement".
Why is that?
I know the OrElse will check the 1st test and if it fails (as it does here) it goes to the next.
What am I missing?
Thanks,
Tom
If I take the following code:
Module Module1
Sub Main()
Dim str As String = String.Empty
Dim j As Integer
Dim k As Integer
str = "aaa"
j = 5
k = 0
If str = String.Empty Or (j / k) Then
Console.WriteLine("Inside If statement")
Else
Console.WriteLine("Inside Else Statement")
End If
Console.ReadLine()
End Sub
End Module
I get a divide by zero error (which was expected). But if I change the Or to OrElse, I don't get the error which I figured I would.
Module Module1
Sub Main()
Dim str As String = String.Empty
Dim j As Integer
Dim k As Integer
str = "aaa"
j = 5
k = 0
If str = String.Empty OrElse (j / k) Then
Console.WriteLine("Inside If statement")
Else
Console.WriteLine("Inside Else Statement")
End If
Console.ReadLine()
End Sub
End Module
Since "str = String.Empty" is false, the next test should go to "(j / k)" which should get an error (as it did before), but prints the "Inside If statement".
Why is that?
I know the OrElse will check the 1st test and if it fails (as it does here) it goes to the next.
What am I missing?
Thanks,
Tom