Results 1 to 6 of 6

Thread: [RESOLVED] could someone help me with some code to increment a mac address please

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2013
    Posts
    122

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    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)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2013
    Posts
    122

    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

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    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.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2013
    Posts
    122

    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
  •  



Click Here to Expand Forum to Full Width