|
-
Apr 18th, 2005, 02:36 PM
#1
Need-a-life Member
Re: Like Operator
I would not use LIKE. Try this:
VB Code:
Option Explicit
Private Sub Form_Load()
TestAndPrint "a.a.a.a"
TestAndPrint "123.123.123.289"
TestAndPrint "1.1.1.1"
TestAndPrint "123.234.111.1"
End Sub
Private Sub TestAndPrint(sIP As String)
Debug.Print sIP & ": " & IsIP(sIP)
End Sub
Private Function IsIP(sIP As String) As Boolean
Dim Octet() As String
Dim i As Integer
Octet = Split(sIP, ".")
IsIP = False
If UBound(Octet) = 3 Then
'We have 4 parameters
IsIP = True
For i = 0 To 3
If IsNumeric(Octet(i)) Then
If Octet(i) < 0 Or Octet(i) > 255 Then
'Not a valid octet
IsIP = False
Exit For
End If
Else
'It's not numeric
IsIP = False
Exit For
End If
Next i
End If
End Function
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 18th, 2005, 02:57 PM
#2
Thread Starter
New Member
Re: Like Operator
Hey McBrain, that's pretty slick
Hey I remember you now, when I was heavy into programming you were part of these forums too, it's all coming back to me now!!
There’s nothing like ‘free elections’ coupled with ‘martial law’. It just screams democracy........ Matt Good
-
Apr 18th, 2005, 03:32 PM
#3
Re: Like Operator
There is a possible bug in the posted IsIp function, because of its use of IsNumeric.
With these test ip's, the function will still return True.
TestAndPrint "123.234.111.1D1"
TestAndPrint "123.234.111.4E1"
TestAndPrint "123.234.111.1,1"
-
Apr 18th, 2005, 03:47 PM
#4
Need-a-life Member
Re: Like Operator
 Originally Posted by brucevde
There is a possible bug in the posted IsIp function, because of its use of IsNumeric.
With these test ip's, the function will still return True.
TestAndPrint "123.234.111.1D1"
TestAndPrint "123.234.111.4E1"
TestAndPrint "123.234.111.1,1"
What the h...?? On what planet "1D1" is numeric?? I think it's because it's considering an hex value. Here's a correction for it.
VB Code:
Option Explicit
Private Sub Form_Load()
TestAndPrint "123.234.111.1D1"
TestAndPrint "123.234.111.4E1"
TestAndPrint "123.234.111.1,1"
TestAndPrint "123.234.111.111"
End Sub
Private Sub TestAndPrint(sIP As String)
Debug.Print sIP & ": " & IsIP(sIP)
End Sub
Private Function IsIP(sIP As String) As Boolean
Dim Octet() As String
Dim i As Integer
Octet = Split(sIP, ".")
IsIP = False
If UBound(Octet) = 3 Then
'We have 4 parameters
IsIP = True
For i = 0 To 3
If IsAllNumeric(Octet(i)) Then
If Octet(i) < 0 Or Octet(i) > 255 Then
'Not a valid octet
IsIP = False
Exit For
End If
Else
'It's not numeric
IsIP = False
Exit For
End If
Next i
End If
End Function
Private Function IsAllNumeric(sNumber As String) As Boolean
Dim i As Integer
IsAllNumeric = True
For i = 1 To Len(sNumber)
If Not IsNumeric(Mid$(sNumber, i, 1)) Then
IsAllNumeric = False
Exit For
End If
Next i
End Function
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|