Private Sub CommandButton1_Click()
If Not is_valid_ip(Me.TextBox1.Value) Then
With Me.TextBox1
.SetFocus
.SelStart = 0
.SelLength = Len(.Value)
End With
End If
'etc
'
'
End Sub
Private Function is_valid_ip(ByVal ip As String) As Boolean
' IP address must be made up of 4 segments and in the format x.x.x.x
' the first segment (ie. X.x.x.x) cannot be 000
' each segment must be within [0,255]
Dim octets As Variant
Dim i As Long
octets = Split(ip, ".")
If UBound(octets) <> 3 Then
is_valid_ip = False
Exit Function
End If
If octets(0) = 0 Then
is_valid_ip = False
Exit Function
End If
For i = LBound(octets) To UBound(octets)
If octets(i) < 0 Or octets(i) > 255 Then
is_valid_ip = False
Exit Function
End If
Next i
is_valid_ip = True
End Function