Keyless Entry

JWalk wrote about a Keyless Entry Hack. “That shouldn’t be too hard to duplicate”, I thought. I get 3,133, but I have four duplicate numbers. Here’s part of my immediate window.

immediate window output

How do I get rid of those duplicates?

Sub MakeKeyCombo()
   
    Dim i As Long, j As Long, k As Long, l As Long, m As Long, n As Long
    Dim sResult As String, sFinal As String
    Dim sCurrent As String
   
    For i = 9 To 1 Step -2
        For j = 9 To 1 Step -2
            For k = 9 To 1 Step -2
                For l = 9 To 1 Step -2
                    For m = 9 To 1 Step -2
                        sCurrent = i & j & k & l & m
                        If InStr(1, sResult, sCurrent) = 0 Then
                            For n = 4 To 0 Step -1
                                If Right$(sResult, n) = Left$(sCurrent, n) Then
                                    sResult = sResult & Right$(sCurrent, 5 – n)
                                    Exit For
                                End If
                            Next n
                        End If
                    Next m
                Next l
            Next k
        Next j
    Next i
   
    Debug.Print sResult
    Debug.Print Len(sResult)
   
    TestResult sResult
   
End Sub
 
Sub TestResult(sResult As String)
 
    Dim i As Long, j As Long, k As Long, l As Long, m As Long
    Dim sCurr As String
   
    For i = 1 To 9 Step 2
        For j = 1 To 9 Step 2
            For k = 1 To 9 Step 2
                For l = 1 To 9 Step 2
                    For m = 1 To 9 Step 2
                        sCurr = i & j & k & l & m
                        If InStr(1, sResult, sCurr) = 0 Then
                            Debug.Print sCurr & ” : Missing”
                        ElseIf Len(sResult) – Len(Replace(sResult, sCurr, “”)) > 5 Then
                            Debug.Print sCurr & ” : Duplicate”
                        End If
                    Next m
                Next l
            Next k
        Next j
    Next i
   
End Sub
Posted in Uncategorized

6 thoughts on “Keyless Entry

  1. Replace this statement:

    sResult = sResult & Right$(sCurrent, 5 – n)

    With these two statements:

    Cells(r + 1, 1) = Right$(sCurrent, 5 – n)
    r = r + 1

    That puts the results in the worksheet. You get 3,125, with no duplicates.

  2. Why does the immediate window still produce a long list of “missing” which are not missing?

    Thanks very much,
    Brett

  3. Oh. I ran the test result after the MakeKeyCombo, but maybe the line -TestResult sResult calls the sub TestResult and passes the sResult string to it. I thought you had to use a Call statement; not true?

    Thanks,
    Brett

  4. Brett: No, you don’t. Call is still available for backward compatability, though. Some people still use it for clarity, but not me. Appropriately named subs should make it obvious that another sub is being called.

  5. Mr. K:
    Sorry to ask a newbie question, but I need your advice on a reinstallation issue.

    I have lost the install code from my backup CD copy of Excel (the original was lost long ago), and I need to reinstall it. Is there a way to get the code out of the 20 digit Product ID?

    Any thoughts for a humble newbie?

    Thanks

    DB


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.