Search Tools Links Login

IsIP Function v2

Posted: 2003-06-01
By: ArchiveBot
Viewed: 87

Filed Under:

Visual Basic 6

No attachments for this post


Updated version of IsIP function. Should clear up all the problems in the last one. Here ya go, =)

Original Author: Daniel M

Code

Private Function IsIP(strIP As String) As Boolean
Dim splitIP() As String, i As Long
IsIP = True 'Starts out as true
splitIP$ = Split(strIP$, ".", -1, 1) 'Split IP To check value
'========================================
'Things we must check to verify IP
'1. Make sure there are 4 sections to IP
'2. Make sure each section of IP is not
' greater than 255
'3. Make sure each section of IP does
' not t contain a negative
'4. Make sure each section of IP is nume-
' ric
'5. Make sure first section of IP is not
' 0
'=======================================
If UBound(splitIP$) <> 3 Then
  IsIP = False 'make sure there is only 4 nodes =)
Else
  For i = 0 To UBound(splitIP$) 'loop through array and check 3 things


   If IsNumeric(splitIP(i)) = False Then
    IsIP = False
    Exit For
   Else
    
    If splitIP(0) = 0 Then 'first digit cannot be 0
     IsIP = False
     Exit For
    End If

    If splitIP(i) > 255 Or splitIP(i) < 0 Then
     IsIP = False
     Exit For
    End If
   End If
  Next i
End If

End Function


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.