word vba 实现获取新的IP地址的方法
比如 原IP地址是 192.168.1.255 +1 变成192.168.2.0 而不是192.168.1.256 --------------------编程问答-------------------- vc 代码 是这样 //获取下一个IP地址,下一个IP地址相当于前一个增加AutoIncCntCString GetNextIPName(CString IP1str,int AutoIncCnt)
{
CString retstr=IP1str;
BYTE ip1=192,ip2=168,ip3=1,ip4=1;
ParseIP(IP1str,ip1,ip2,ip3,ip4);
DWORD nextip=0;
nextip=nextip*256+ip1;
nextip=nextip*256+ip2;
nextip=nextip*256+ip3;
nextip=nextip*256+ip4;
nextip=nextip+AutoIncCnt;
retstr.Format("%d.%d.%d.%d",BYTE(nextip/256/256/256),BYTE(nextip/256/256%256),BYTE(nextip/256%256),BYTE(nextip%256));
return retstr;
}
--------------------编程问答-------------------- 楼主试下这个:
Function GetNextIPName(IP1str As String, ByVal AutoIncCnt As Long) As String--------------------编程问答-------------------- 简化一下:
Dim aIPdn(3) As Long, aIPds() As String
Dim i&, V&, C&, sR$
aIPds = Split(IP1str, ".")
For i = 0 To 3: aIPdn(i) = aIPds(i): Next
C = 0
For i = 3 To 0 Step -1
V = C + aIPdn(i) + (AutoIncCnt And 255)
aIPdn(i) = V And 255
AutoIncCnt = AutoIncCnt \ 256
C = V \ 256
If ((C Or AutoIncCnt) = 0) Then Exit For
Next
sR = aIPdn(0)
For i = 1 To 3: sR = sR & "." & aIPdn(i): Next
GetNextIPName = sR
End Function
Function GetNextIPName(IP1str As String, ByVal AutoIncCnt As Long) As String
Dim aIPdn(3) As Long, aIPds() As String
Dim i&, V&, C&, sR$
aIPds = Split(IP1str, ".")
For i = 0 To 3: aIPdn(i) = aIPds(i): Next
C = 0: sR = ""
For i = 3 To 0 Step -1
V = C + aIPdn(i) + (AutoIncCnt And 255)
AutoIncCnt = AutoIncCnt \ 256
sR = "." & (V And 255) & sR
C = V \ 256
Next
GetNextIPName = Mid$(sR, 2)
End Function
补充:VB , VBA