put ip address in textBox what to add more?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 2146 Views - Last Post: 15 June 2015 - 10:50 AM Rate Topic: -----

#1 mercy_angel   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 412
  • Joined: 28-February 13

put ip address in textBox what to add more?

Posted 11 June 2015 - 01:41 PM

What should I add more? I think about restiction about 0-255 but don't know how to add that..
 Private Sub txtIP_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtIP.KeyPress
        e.Handled = Not Char.IsControl(e.KeyChar) AndAlso Not New Regex("^(\d{1,3}\.)?(\d{1,3}\.)?(\d{1,3}\.)?(\d{1,3})?$").IsMatch(txtIP.Text.Insert(txtIP.Selectionstart, e.KeyChar.ToString))
    End Sub

    Private Sub txtIP_TextChanged(sender As Object, e As EventArgs) Handles txtIP.TextChanged
        Static oldText As String = ""
        If Not New Regex("^(\d{1,3}\.)?(\d{1,3}\.)?(\d{1,3}\.)?(\d{1,3})?$").IsMatch(txtIP.Text) Then txtIP.Text = oldText
        oldText = txtIP.Text
    End Sub

   


Is This A Good Question/Topic? 0
  • +

Replies To: put ip address in textBox what to add more?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14501
  • View blog
  • Posts: 58,131
  • Joined: 12-June 08

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 01:53 PM

Quote

What should I add more?

More of what?
Was This Post Helpful? 0
  • +
  • -

#3 mercy_angel   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 412
  • Joined: 28-February 13

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 01:56 PM

More of being that program easily to use. I can here add for example:333.333.333.333 but, there is not 333 in Ip range..
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14501
  • View blog
  • Posts: 58,131
  • Joined: 12-June 08

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 02:01 PM

I would think the validation event would be a better option. As is something more simple in terms of splitting a string apart by the '.'.. checking there are four parts after the split and that each are greater than 0 and less than 256.
Was This Post Helpful? 0
  • +
  • -

#5 mercy_angel   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 412
  • Joined: 28-February 13

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 02:07 PM

Can you help me with that? i didnt use validating so far..
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14501
  • View blog
  • Posts: 58,131
  • Joined: 12-June 08

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 02:11 PM

No, I am not going to write it for you. Look at the events for the textbox (in the designer, in the properties window, lick on the little lightening bolt)..

You can also read about the events here:
https://msdn.microso...=vs.110%29.aspx

In a similar turn of events you can find the string's function called "split" in the documentation as well.
https://msdn.microso...=vs.110%29.aspx
Was This Post Helpful? 0
  • +
  • -

#7 mercy_angel   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 412
  • Joined: 28-February 13

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 02:21 PM

I did like this, maybe its better for me..Just in TextChanged event add this
 Dim minimum = 0
        Dim maximum = 255
        Dim number As Int32
       
        If number < minimum OrElse number > maximum Then
            Dim message = String.Format("Please enter an integer between {0} and {1}!",
                          minimum, maximum)
            MessageBox.Show(message)
            Return
        End If



But when put 555, there is no error..Why?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14501
  • View blog
  • Posts: 58,131
  • Joined: 12-June 08

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 02:25 PM

03	       Dim number As Int32
04	       
05	       If number < minimum OrElse number > maximum Then


I would believe not setting the variable 'number' would be a bad thing.
Was This Post Helpful? 0
  • +
  • -

#9 mercy_angel   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 412
  • Joined: 28-February 13

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 02:36 PM

Dim number = Integer.Parse(txtIP.Text)



This didn't work...And cant use dot (".")

This post has been edited by mercy_angel: 11 June 2015 - 02:37 PM

Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14501
  • View blog
  • Posts: 58,131
  • Joined: 12-June 08

Re: put ip address in textBox what to add more?

Posted 11 June 2015 - 02:41 PM

Well.. yeah. A number with a '.' is just a decimal, right? A number with three '.' is not a recognized number, but more of a string. This is why I suggested splitting the string around the '.'.

How about this alternative idea - have four textboxes for each four parts of the octet. Validate each.
Was This Post Helpful? 0
  • +
  • -

#11 mercy_angel   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 412
  • Joined: 28-February 13

Re: put ip address in textBox what to add more?

Posted 12 June 2015 - 05:56 AM

Can I add four textBoxes, and some labels for dot (.) and than just, because i must that ip address enter in another textbox, just combine strings with that 4 textboxes, and add that all?

And can i check just to enter for textbox that only allowed numbers from 0-255...
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw   User is offline

  • head thrashing
  • member icon

Reputation: 6627
  • View blog
  • Posts: 27,091
  • Joined: 12-December 12

Re: put ip address in textBox what to add more?

Posted 12 June 2015 - 06:23 AM

Yes.

You could use four NumericUpDown controls and set the range of each's values between 0 and 255.
Was This Post Helpful? 0
  • +
  • -

#13 mercy_angel   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 412
  • Joined: 28-February 13

Re: put ip address in textBox what to add more?

Posted 12 June 2015 - 06:30 AM

Ok, i will look for that event.
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14501
  • View blog
  • Posts: 58,131
  • Joined: 12-June 08

Re: put ip address in textBox what to add more?

Posted 12 June 2015 - 06:32 AM

NumericUpDown control is a control and not an event.

Again - you can look into the .NET documentation and see this.

Example:
https://msdn.microso...=vs.110%29.aspx
Was This Post Helpful? 0
  • +
  • -

#15 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 666
  • Joined: 01-October 08

Re: put ip address in textBox what to add more?

Posted 12 June 2015 - 10:13 AM

View Postmercy_angel, on 12 June 2015 - 08:30 AM, said:

Ok, i will look for that event.


Is this you? http://www.vbforums....l=1#post4891727

You are over thinking this. Parse the IPAddress (there is a method for that) and if needed look at each individual byte(there is a method that will return each part of the IPAddress.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3