[RESOLVED] could someone help me with some code to increment a mac address please
i could do with a code that would increment a mac address by 1
example
dim mymac = "00:00:00:00:00:ff"
some code
msgbox(mymac) ' mymac = "00:00:00:00:01:00"
not sure where to start :)
Re: could someone help me with some code to increment a mac address please
I assume there are easier ways of doing it but this works.
Code:
Option Explicit
Private Sub Command1_Click()
Dim strMac As String
Dim i As Integer
strMac = "00:00:00:00:09:FE"
For i = 0 To 10
strMac = GetNextMacAddress(strMac)
Debug.Print strMac
Next i
End Sub
Private Function GetNextMacAddress(ByVal MacAddress As String) As String
Dim strHexParts() As String
Dim intPart As Integer
Dim i As Integer
strHexParts = Split(MacAddress, ":")
For i = UBound(strHexParts) To 0 Step -1
intPart = CInt("&H" & strHexParts(i)) + 1
If intPart < 256 Then
strHexParts(i) = CStr(Hex(intPart))
strHexParts(i) = Right("0" & strHexParts(i), 2)
Exit For
Else
strHexParts(i) = "00"
End If
Next i
GetNextMacAddress = Join(strHexParts, ":")
End Function
Re: could someone help me with some code to increment a mac address please
Code:
Public Function IncrementMACAddress(ByRef MAC_Address As String) As String
Dim Hi As Long, Lo As Long
IncrementMACAddress = Replace(MAC_Address, ":", vbNullString)
Hi = CLng("&H" & Left$(IncrementMACAddress, 6&))
Lo = CLng("&H" & Right$(IncrementMACAddress, 6&))
If Lo < &HFFFFFF Then
Lo = Lo + 1&
Else
Lo = 0&
If Hi < &HFFFFFF Then
Hi = Hi + 1&
Else
Err.Raise 6& 'Overflow
End If
End If
IncrementMACAddress = Replace(Format$(Hex$(Hi), "@@:@@:@@") & ":" & _
Format$(Hex$(Lo), "@@:@@:@@"), " ", "0")
End Function
Re: could someone help me with some code to increment a mac address please
i have tried both methods and they both work well :)
thanx guys that helps a lot.
also another question :)
if you were going to make a function to test your internet speed how would you go about it.
im thinking just download a file and calculate the download time with the size of the file.
if you agree, where should i be looking
Re: could someone help me with some code to increment a mac address please
Your 2nd question should be on another thread. If this was resolved then you can mark it.
Re: could someone help me with some code to increment a mac address please