|
-
May 22nd, 2013, 12:52 PM
#1
Thread Starter
Lively Member
[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
-
May 22nd, 2013, 04:18 PM
#2
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
-
May 22nd, 2013, 04:27 PM
#3
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
Last edited by Bonnie West; May 22nd, 2013 at 04:48 PM.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
May 23rd, 2013, 03:47 AM
#4
Thread Starter
Lively Member
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
-
May 23rd, 2013, 03:51 AM
#5
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.
-
May 23rd, 2013, 04:08 AM
#6
Thread Starter
Lively Member
Re: could someone help me with some code to increment a mac address please
ok good point
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|