IP textbox

Nazgulled

Centurion
Joined
Jun 1, 2004
Messages
119
Is it possible to have a textbox to act like the ones in the network connections in the TCP/IP properties? how?
 
The .NetFramework 2.0 has a masked textbox control which allows you to set a mask for input. You also need to verify the values entered, making sure that each number is less than 256.
 
thanks... however, i'm having difficulties to convert the string of the masked textbox to int to see if it's less than 256...

Code:
Private Sub mtxtLIP_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles mtxtLIP.KeyUp
        Dim segments As String() = mtxtLIP.Text.Split(".")
        Dim segment As String

        For Each segment In segments
            If segment > 255 Then
                picLIP.Visible = True
            Else
                picLIP.Visible = False
            End If
        Next
    End Sub

Obviously, this doesn't work... but I tried many int conversions and none of them worked...
 
Visual Basic:
 If int.Parse(segment) > 255 Then
*NB it sounds like your using .Net 2.0 in which case you could use TryParse(), if you do however note the overload is different to Parse()
 
Just to add my own 2 pence worth...

When using VB I would always recommend putting Option Strict On at the top of every source file. In fact I would make this the default under Tools->Options->Projects And Solutions->VB Defaults
 
Cags said:
Visual Basic:
 If int.Parse(segment) > 255 Then
*NB it sounds like your using .Net 2.0 in which case you could use TryParse(), if you do however note the overload is different to Parse()


That didn't work, nor Integer.parse() I had to solve it with the tryparse()

thanks...

I thought I had option strict on but I guess I was wrong. If I enable it globally in the options, I'll still have to add it to my program right? Unless I start to create a new project... right or wrong?
 
I did a google search for "IP Address textbox c#" without the quotes and came up with the following:
http://www.codeproject.com/cs/miscctrl/IPAddressTextBox.asp

He address a LOT more issues that you were/are probably interested in, but still might prove useful. Glad to see you got the parsing fixed. :)

Note: I didn't actually look in detail at what was posted so I'm not saying it's definitely an example of clean code. Just thought I'd offer up the link in case it happens to work for you.

-ner
 
Back
Top