|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > IP string trouble |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|