Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

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..

    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

Open in new window

Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

here:
    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        If MyIPAddress = "0" AndAlso 
MyIPAddress = OldIPAddress AndAlso  
MyIPAddress.StartsWith("168.") AndAlso 
MyIPAddress.StartsWith("169.") AndAlso 
MyIPAddress.StartsWith("192.") Then
                                Debug.Print("all good")

                        End If
                    End If
                End If
            End If
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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("168.") OR _
                   MyIPAddress.StartsWith("169.") OR _
                   MyIPAddress.StartsWith("192.") Then
                                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