I am writing an application that needs to do some validation on user-entered IP addresses. I took a stab at writing my own code, but figured somebody must have doen something like this before. I need to check the following:
- there are 4 octets seperated by 3 periods (.)
- each octet must be between 1 and 255
Here's the beginning of what I wrote with msgbox's that show me what each octet is.
Private Sub Split_IP()
Dim strIP As String
Dim pos As Long
Dim pos2 As Integer
Dim first_oct As Integer
Dim second_oct As Integer
Dim third_oct As Integer
Dim length As Integer
txtIP.SetFocus
strIP = txtIP.Text
pos = InStr(strIP, "."
first_oct = Left(strIP, pos)
MsgBox "first_oct = " & first_oct & ""
pos = pos + 1
second_oct = Mid(strIP, pos, (InStr([pos], strIP, "." - pos))
MsgBox "second_oct = " & second_oct & ""
pos = pos + Len(second_oct)
third_oct = Mid(strIP, pos, (InStr([pos], strIP, "."))
MsgBox "third_oct = " & third_oct & ""
End Sub
This works up until the 3rd octet. Anyone have any suggestions?
Thanks in advance!!
Don
- there are 4 octets seperated by 3 periods (.)
- each octet must be between 1 and 255
Here's the beginning of what I wrote with msgbox's that show me what each octet is.
Private Sub Split_IP()
Dim strIP As String
Dim pos As Long
Dim pos2 As Integer
Dim first_oct As Integer
Dim second_oct As Integer
Dim third_oct As Integer
Dim length As Integer
txtIP.SetFocus
strIP = txtIP.Text
pos = InStr(strIP, "."
first_oct = Left(strIP, pos)
MsgBox "first_oct = " & first_oct & ""
pos = pos + 1
second_oct = Mid(strIP, pos, (InStr([pos], strIP, "." - pos))
MsgBox "second_oct = " & second_oct & ""
pos = pos + Len(second_oct)
third_oct = Mid(strIP, pos, (InStr([pos], strIP, "."))
MsgBox "third_oct = " & third_oct & ""
End Sub
This works up until the 3rd octet. Anyone have any suggestions?
Thanks in advance!!
Don