Address.ToString().Remove(10, 3)

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
Is there a way to make the second parameter in Remove(10,3) be a variable number.

What I am doing is comparing the PPP Adapter IP Address to a constant IP Address that is always going to be 10 characters, but the string I am removing from can have 3,4, or 5 characters.

I have:

VB.NET:
Dim pppIPAddresses As String = "170.170.70"

If pppIPAddresses = (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Remove(10, 3)) Then
' displays the IP Address for verification
TextBox2.Text = (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Remove(10, 3))
Return True
End If
End If

Thanks
CoachBarker
 
Maybe you're only interested in "170.170.70", so you could also use StartsWith method. Else if you were only interested in any first three parts you could use the LastIndexOf method to find the index of the last "."
 
Can I use two Booleans in one Function,here is the whole Function;

VB.NET:
Public Function VPNRunning() As Boolean
        Try
            Dim pppAddress() As System.Net.NetworkInformation.NetworkInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
            For Each cInterface As System.Net.NetworkInformation.NetworkInterface In pppAddress
                If cInterface.NetworkInterfaceType = Net.NetworkInformation.NetworkInterfaceType.Ppp Then

' Text box is for validation purposes only when testing
                    TextBox1.Text = (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString())

' The second Boolean using the StartsWith method would have to belong 
' to the following line of code

                    If SUIPAddresses = (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Remove(10)) Then

' Text box is for validation purposes only when testing

                        TextBox2.Text = (cInterface.GetIPProperties.UnicastAddresses.Item(0).Address.ToString().Remove(10))
                        MsgBox("VPN is running")
                        Return True
                    End If
                End If
            Next
            Return False
        Catch ex As Exception
            'MessageBox.Show(ex.ToString())
        End Try
    End Function

And then for now the Function is tested by a button click event;

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If VPNRunning() = False Then
            If MessageBox.Show("SU VPN is not running right now, Please Log into the VPN?.", "VPN not running", _
                               MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then
                Dim prc As New Process
                prc = Process.Start("rasphone.exe")
                prc.WaitForExit()
            End If
        End If
    End Sub

Or does using the remove method with only one parameter going to cause a problem?

Thanks for your comments
CoachBarker
 
Back
Top