Convert StringIP to NumericIP
Converts a string ip address ("192.168.0.1") to a Long number (3232235521). One of the resons to do this would be to store IP addresses in databases. Numbers greatly reduce the size required to store this information.
Original Author: Lewis E. Moten III
Inputs
asNewIP - String IP address ("192.168.0.1") to convert to a number.
Assumptions
This function assumes that your IP address has 4 integers delimited by decimals and that the numbers range from 0 to 255.
Returns
Returns a Long Integer representing the IP address (3232235521)
Side Affects
If storing number within an Access Database, The variable type "Long" ranges from -2147483648 to 2147483647. You will need to subtract 2147483648 from the number before querying the database.
API Declarations
Copyright (C) 1999, Lewis Moten. All rights reserved.
Code
' ----- for vb6 users -----
Function IP_Dotless#(ByVal ipAddress As String)
Dim numArray As Variant
numArray = Split(ipAddress$, ".")
IP_Dotless = (numArray(0) * 256 ^ 3) + _
(numArray(1) * 256 ^ 2) + _
(numArray(2) * 256 ^ 1) + _
numArray(3)
End Function
' ----- for vb5 and below users -----
Function IP_Dotless# (ByVal ipAddress As String)
IP_Dotless = (Val(GetWord$(ipAddress, 1, ".")) * 256 ^ 3) + (Val(GetWord$(ipAddress, 2, ".")) * 256 ^ 2) + (Val(GetWord$(ipAddress, 3, ".")) * 256 ^ 1) + (Val(GetWord$(ipAddress, 4, ".")))
End Function
Function CountWords& (ByVal inWord$, ByVal inSep$)
Dim strTempA$
Dim strTempB$
Dim lngTempA&
Dim lngTempB&
Dim lngRet&
On Error Resume Next
inWord$ = inWord$ + inSep$
For lngRet& = 1 To Len(inWord$)
strTempA$ = Mid$(inWord$, lngRet&, Len(inSep$))
strTempB$ = strTempB$ + strTempA$
If strTempA$ = inSep$ Then
lngTempA& = Len(strTempB$) - Len(inSep$)
strTempB$ = Left$(strTempB$, lngTempA&)
lngTempB& = lngTempB& + 1
strTempB$ = ""
End If
Next lngRet&
CountWords& = lngTempB&
End Function
Function GetWord$ (ByVal inWord$, ByVal inCount&, ByVal inSep$)
Dim strTempA$
Dim strTempB$
Dim lngTempA&
Dim lngTempB&
Dim lngRet&
On Error Resume Next
inWord$ = inWord$ + inSep$
For lngRet& = 1 To Len(inWord$)
strTempA$ = Mid$(inWord$, lngRet&, Len(inSep$))
strTempB$ = strTempB$ + strTempA$
If strTempA$ = inSep$ Then
lngTempA& = Len(strTempB$) - 1
strTempB$ = Left$(strTempB$, lngTempA&)
lngTempB& = lngTempB& + 1
If lngTempB& = inCount& Then
GetWord$ = strTempB$
Exit Function
End If
strTempB$ = ""
End If
Next lngRet&
GetWord$ = ""
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.