#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    7
    Rep Power
    0

    IP string trouble


    let's say I have the string 0.0.0.0 on text1.text I know how to make it so that text2.text displays 0.0. using this line.

    iprange = Left(Text1.text, InStr(Text1.text, ".") + 2)
    Text2.text = iprange

    what i want to know is, if the IP address 255.255.255.255 goes on text1.text with my code, i only get this on text2.text; 255.25

    how can I always get this format: X.X. everytime without cutting it down due to the change of numbers of character
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    Plenty of ways to do this. One way to do this is note that instr has a parameter to specify starting point, so you could call instr to find the first period, then call it again with the position of the first period + 1 as the starting point. This will find the position of the second period and then you can extract the string.
    Code:
        Dim foo As String
        Dim iprange As String
        foo = Text1.text
        iprange = Left(foo, InStr(InStr(foo, ".") + 1, foo, ".") - 1)
        MsgBox iprange
    Another way is to use the split function to split the string into an array, using "." as the separator character. After that, it's just a matter of combining the first two array elements.
    Code:
        Dim foo As String
        Dim iprange As String
        Dim parts() As String
        foo = Text1.text
        parts = Split(foo, ".")
        iprange = parts(0) & "." & parts(1)
        MsgBox iprange
    Hope this helps

IMN logo majestic logo threadwatch logo seochat tools logo