'Возвращает массив строк
Public Function IPCalc(strIP As String, Optional ToBin As Boolean = False) As Variant
Dim Arr As Variant
Arr = Split(strIP, ".")
Arr(2) = CStr((Arr(2) \ 4) * 4 + 3)
Arr(3) = CStr(255)
If ToBin Then
Dim i As Integer
For i = 0 To UBound(Arr)
Arr(i) = LongToBinStr(CLng(Arr(i)), 8)
Next i
End If
IPCalc = Arr
End Function
Public Function LongToBinStr(ByVal Number As Long, Optional Digits As Long = 32) As String
Dim i As Long
Const ZERO As String = "0"
Const ONE As String = "1"
LongToBinStr = String(Digits, ZERO)
For i = Digits To 1 Step -1
If Number Mod 2 Then
Mid$(LongToBinStr, i, 1) = ONE
End If
Number = Number \ 2
If Number = 0 Then Exit Function
Next i
End Function
|