XK8ER
asked on
vb.net using and or andalso
Hello,
I would like to know what are the options of using And or AndAlso to get the same results that I have here..
I would like to know what are the options of using And or AndAlso to get the same results that I have here..
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
If MyIPAddress = "0" Then
If MyIPAddress = OldIPAddress Then
If MyIPAddress.StartsWith("168.") Then
If MyIPAddress.StartsWith("169.") Then
If MyIPAddress.StartsWith("192.") Then
Debug.Print("all good")
End If
End If
End If
End If
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not sure logic above makes sense...
If MyIPAddress = "0" then address can not be another value to test inside If block...
Maybe...
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
If MyIPAddress <> "0" Then
If MyIPAddress <> OldIPAddress Then
If MyIPAddress.StartsWith("16 8.") OR _
MyIPAddress.StartsWith("16 9.") OR _
MyIPAddress.StartsWith("19 2.") Then
Debug.Print("all good")
End If
End If
End If
End Sub
If MyIPAddress = "0" then address can not be another value to test inside If block...
Maybe...
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
If MyIPAddress <> "0" Then
If MyIPAddress <> OldIPAddress Then
If MyIPAddress.StartsWith("16
MyIPAddress.StartsWith("16
MyIPAddress.StartsWith("19
Debug.Print("all good")
End If
End If
End If
End Sub
you should not use or/and (but prefer orelse/andalso).
the explanation is at http://emoreau.com/Entries/Articles/2008/04/Short-circuiting-mainly-in-VBNet-and-SQL-Server.aspx
the explanation is at http://emoreau.com/Entries/Articles/2008/04/Short-circuiting-mainly-in-VBNet-and-SQL-Server.aspx
Open in new window