Home > Software engineering >  Word vba to realize the access to the new IP address
Word vba to realize the access to the new IP address

Time:10-25

Such as the original IP address is 192.168.1.255 + 1 into 192.168.2.0 not 192.168.1.256

CodePudding user response:

Under the vc code is so//get an IP address, an IP address is equivalent to the previous increase AutoIncCnt
Cstrings GetNextIPName (cstrings IP1str, int AutoIncCnt)
{
Cstrings 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. The Format (" % d % d, % d, % d ", BYTE (nextip/256/256/256), a BYTE (256% nextip/256/256), and BYTE (256% nextip/256), a BYTE (256) nextip %);
Return retstr;
}

CodePudding user response:

The building Lord, try this:
 Function GetNextIPName (IP1str As String, ByVal AutoIncCnt As Long) As String 
Dim aIPdn (3) As Long, aIPds () As String
Dim i& V& C& The 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 (Or AutoIncCnt (C)=0) Then the Exit For
Next
The sR=aIPdn (0)
For I=1 To 3: sR=sR & amp; ". "& amp; AIPdn (I) : Next
GetNextIPName=sR
End the Function

CodePudding user response:

Simplify:
 Function GetNextIPName (IP1str As String, ByVal AutoIncCnt As Long) As String 
Dim aIPdn (3) As Long, aIPds () As String
Dim i& V& C& The 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
The sR=". "& amp; And 255 (V) & amp; The sR
C=V \ 256
Next
GetNextIPName=Mid $(sR, 2)
End the Function

  •  Tags:  
  • VBA
  • Related