Function Long2IP()
This function converts a numeric value into a string containing an IP address in dot notation.
This can be used to generate IP addresses with the auto-increment functionality of Calc.
REM ***** BASIC *****
Function Long2IP(addr as Double) as String
DIM res as String
a = fix(addr / 16777216)
b = fix(( addr - 16777216 * a) / 65536)
c = fix(( addr - 16777216 * a - 65536 * b ) / 256)
d = fix( addr - 16777216 * a - 65536 * b - 256 * c )
res = Format(a, "000") + "."
res = res + Format(b, "000") + "."
res = res + Format(c, "000") + "."
res = res + Format(d, "000")
Long2IP = res
End Function
Function Main(addr as Variant) as String
DIM res as String
IF IsMissing(addr) THEN
res = "Missing Argument"
ELSEIF IsArray(addr) THEN
res = "Array"
ELSEIF IsNumeric(addr) THEN
res = Long2IP(addr)
ELSE
res = "String"
END IF
Main = res
End Function
I place this code into the public domain.
| Attachment | Size |
|---|---|
| long2ip.txt | 684 bytes |
