Jump to content

Need some assistance with a huge "if" statement


Dainish
 Share

Recommended Posts

Hello,

I was hoping to get a bit of help with a script I'm working on at work. First, a little background to explain what the script is for:

Essentially, I work in Security and am responsible for checking out keys to on-site personnel, so that they can open specific locks. The people who check out the keys will tell me that they need to get into a certain lock, and currently I have to look through a massive printed (8-page) spreadsheet to see which key goes to that lock.

I started work on a script to assist with this process, and so far it works great! My problem is that the only way I can figure out how to make it work is with a MASSIVE "if" statement; I was wondering if someone could be so kind as to help me come up with a more efficient method of doing the same thing?

I am experienced in programming and computers in general, but I am somewhat of a n00b at AutoIT. I have consulted the built-in Help file, but honestly I'm not quite sure what to look for there. Any help is greatly appreciated! :)

Here is the script so far:

#cs -----------------------------------------------------------------------------------------------

Key Lookup Utility, version 1.0 BETA
Author: Dain Schroeder
Purpose: To make it easier to determine what key is needed for a specific rack
Started: October 20, 2012

#ce -----------------------------------------------------------------------------------------------

;First, because this script uses functions, we need to declare our variables as global.
Global $rack = 0
Global $key = 0

;This 'While' statement contains the heart of the script, and forces it to loop forever
;(because I've told it to loop as long as 1 equals 1 - which is forever).
While 1 = 1
GetRack()
GiveKey()
Wend

;The GetRack function is the initial popup which asks what rack we want to lookup.
Func GetRack()
;Alright, let's get this show on the road. First, we need to ask the user what rack to look up.
;We will now invoke an input box (and a loop, to ensure that all errors are accounted for).
Local $bLoop = 1
While $bLoop = 1
$rack = InputBox("Dain's Key Lookup Utility", "Please enter the rack that you need to get into. This utility will then tell you which key opens that rack.", "Type a rack in the format 'CO1 AB123'", " M9")
if @error = 1 Then
MsgBox(4096, "Peace out, homie", "Thanks for using Dain's Key Lookup Utility.")
Exit
Else
; They clicked OK, but did they type the right thing?
If $rack = " " Then
MsgBox(4096, "YOU BROKE IT!", "Oops - looks like you left the box empty. Please try again, or press Cancel to quit.")
Else
$bLoop = 0
EndIf
EndIf
WEnd
EndFunc

;The GiveKey function is where we check what key is needed and inform the user.
Func GiveKey()
;Alright, so now we know which rack the user needs to locate the key for. Now let's
;get to the real heart of this utility and figure out which key they need. We'll do this
;by making a giant "If" statement. It's a simple but effective way of allowing the user to
;type anything, and it makes it easy to update this utility as new racks are added.
If $rack = "CO1 AM123" Then
$key = "209 or 210"
MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "!")
ElseIf $rack = "CO1 AM124" Then
$key = "209 or 210"
MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "!")
ElseIf $rack = "CO1 AR111" Then
$key = "171"
MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "!")
ElseIf $rack = "CO1 DN102" Then
$key = "133 or 134"
MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
ElseIf $rack = "CO1 DN103" Then
$key = "133 or 134"
MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
EndIf

EndFunc

Currently, my only plan is to add many, many more "else if" statements to accommodate for all the keys I have. However, if someone knows of a better way, that'd be fantastic!

Like I said, any help at all is greatly appreciated. Thanks in advance!

Link to comment
Share on other sites

Global $rack = 0
Global $key = 0

While 1
    GetRack()
    GiveKey()
WEnd

Func GetRack()
    Do
        $rack = InputBox("Dain's Key Lookup Utility", "Please enter the rack that you need to get into. This utility will then tell you which key opens that rack.", "Type a rack in the format 'CO1 AB123'", " M9")
        If @error Then
            MsgBox(4096, "Peace out, homie", "Thanks for using Dain's Key Lookup Utility.")
            Exit
        Else
            $validate = (StringLen($rack) = 9)
            If Not $validate Then MsgBox(4096, "YOU BROKE IT!", "Oops - looks like you left the box empty. Please try again, or press Cancel to quit.")
        EndIf
    Until $validate
EndFunc

Func GiveKey()
    Switch $rack
        Case "CO1 AM123", "CO1 AM124"
            $key = "209 or 210"
            MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "!")
        Case "CO1 AR111"
            $key = "171"
            MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "!")
        Case "CO1 DN102", "CO1 DN103"
            $key = "133 or 134"
            MsgBox(4096, "Dain's Key Lookup Utility", "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
        Case Else
            MsgBox(4096, 'Error', 'Error')
    EndSwitch
EndFunc

Edited by AZJIO
Link to comment
Share on other sites

Assuming the racks are unique use an Associative Array or dictionary. In AutoIt you can use an object called Scripting.Dictionary. It should be on most Windows systems if they are XP or later. I wrote a couple of wrapper functions to make using it easier. But the idea behind a Dictionary is that the key can be a name(string) and you can get the value using the key. It's like ti automatically looks it up without using a whole database.

Here's a small example

;test the diectionary
$myDictionary = _AssocArray()
If Not $myDictionary Then ; creation failed
MsgBox(0x1010,"Test","Dictionary Creation Failed!")
Exit
EndIf

$myDictionary("RackNameJoe") = "Key55"
$myDictionary("RackNameHarry") = "Key21"
$myDictionary("RackNameJack") = "Key1001"
; etc..
; now look up a key
; always check with Exists method to avoid drawing a blank
If $myDictionary.Exists("RackNameJack") Then
$key = $myDictionary("RackNameJack")
MsgBox(0x1040,"Test","Key for RackNameJack is " & $key)
EndIf
; yadda yadda
; if not ending your program right away and you are done with the dictiony use destroy
; fo free memory
_AssocArrayDestroy($myDictionary)


;use Scripting.Dictionary object for simple associative arrays
Func _AssocArray()
Local $aArray = ObjCreate("Scripting.Dictionary")
If @error Then
Return SetError(1, 0, 0)
EndIf
$aArray.CompareMode = 1
Return $aArray
EndFunc ;==>_AssocArray

Func _AssocArrayDestroy(ByRef $aArray)
If Not IsObj($aArray) Then
Return False
EndIf
$aArray.RemoveAll()
$aArray = 0
Return True
EndFunc ;==>_AssocArrayDestroy
Edited by MilesAhead
Link to comment
Share on other sites

Thanks for the assistance, everyone - I greatly appreciate it! It's wonderful to have a resource like this forum to take my problems to. I just knew there must be a more efficient way to tackle this than with a massive "if" statement.

I think in this instance I'll use "cases," as a couple of you suggested.

AZJIO, thanks for taking it a step further and also showing me an infinitely better way to write the GetRack() function.

Link to comment
Share on other sites

It looks like you may have multiple doors that have the same lock (tumbler), and then you may have multiple keys for each of those tumblers. For instance you have 6 doors with 4 different locks, and 10 assorted keys.

You'd need to have separate tables... One listing the different locks/tumblers, another telling which location had which tumbler, and another showing which keys fit which tumbler. Something like this, maybe...

#include <GuiComboBox.au3>
#include <Array.au3>

Global $str, $iTumbler, $iRow, $sorted
Global $aTumblers[5] = [4, "E4591", "2792", "A239", "GR77"]
Global $aLocations[7][2] = [[6], _ ; location, tumbler
    ["CO1 AM123", 1], _
    ["CO1 AM124", 1], _
    ["CO1 AR111", 3], _
    ["CO1 DN102", 4], _
    ["CO1 DN103", 2], _
    ["CO1 DN107", 4]]
Global $aKeys [11][3] = [[10], _ ; key number, tumbler, checked_out_to
    ["133", 4, ""], _
    ["135", 4, ""], _
    ["171", 1, ""], _
    ["208", 2, ""], _
    ["209", 2, ""], _
    ["210", 2, ""], _
    ["211", 2, ""], _
    ["321", 3, ""], _
    ["322", 3, ""], _
    ["172", 1, ""]]

; Initialization
For $x = 1 to $aLocations[0][0] ; store tumbler number for each location as variable for searches
    $str = "__" & StringReplace($aLocations[$x][0], " ", "_")
    Assign($str, $aLocations[$x][1])
Next
_ArraySort($aKeys, 0, 1, 0, 1) ; sort keys on column 1 (tumbler number)
;While $sorted = 0 ; sub-sort on column 0 (key number)
;    $sorted = 1
;    For $x = 1 to $aKeys[0][0] -1
;        If $aKeys[$x][1] = $aKeys[$x + 1][1] _
;       And $aKeys[$x][0] > $aKeys[$x + 1][0] Then
;           $str = $aKeys[$x + 1][0]
;           $aKeys[$x + 1][0] = $aKeys[$x][0]
;           $aKeys[$x][0] = $str
;           $sorted = 0
;       EndIf
;    Next
;WEnd
For $x = 1 to $aKeys[0][0] ; store first occurance of tumbler as variable for searches
    $str = "__" & $aKeys[$x][1]
    If Not IsDeclared($str) Then Assign($str, $x)
Next
$str = ""
For $x = 1 to $aLocations[0][0] ; load combobox string for locations
    $str &= $aLocations[$x][0] & "|"
Next
$str = StringTrimRight($str, 1)

; Build GUI
GUICreate("Dain's Key Finder", 350, 60, 300, 300)
GUICtrlCreateLabel("LOCK LOCATION", 10, 10, 90, 16)
$cLocations = GUICtrlCreateCombo("", 10, 28, 90, 16)
GUICtrlCreateLabel("TUMBLER", 115, 10, 60, 16, 1)
$cTumbler = GUICtrlCreateLabel("", 115, 30, 60, 16, 1)
GUICtrlSetBkColor($cTumbler, 0xFFFFFF)
GUICtrlCreateLabel("KEY NUMBER(S)", 190, 10, 150, 16, 1)
$cKeys = GUICtrlCreateLabel("", 190, 30, 150, 16, 1)
GUICtrlSetBkColor($cKeys, 0xFFFFFF)
GUICtrlSetData($cLocations, $str)
GUISetState()

; Main loop
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $cLocations
            $iRow = _GUICtrlComboBox_GetCurSel($cLocations) + 1
            $str = "__" & StringReplace($aLocations[$iRow][0], " ", "_")
            $iTumbler = Eval($str)
            GUICtrlSetData($cTumbler, $aTumblers[$iTumbler])
            $str = ""
            For $x = Eval("__" & $iTumbler) to $aKeys[0][0]
                If $aKeys[$x][1] <> $iTumbler Then ExitLoop
                $str &= $aKeys[$x][0] & " "
            Next
            GUICtrlSetData($cKeys, $str)
        Case -3
            ExitLoop
    EndSwitch
WEnd

Edit: Your next step might be to use the third column of the $aKeys array. If left blank, then the key is in your possession, if not, that column could contain the user name who has the key checked out. Of course you'd have to add logic to set that field, then save the array to a file at the end of the program, so that you could load it again at program start and retain values between executions of your script.

Edited by Spiff59
Link to comment
Share on other sites

Or as alternative, have an array key building function that builds a unique string from the factors. The data portion of an AssocArray can itself be an array or object. It's not limited to say, one key(as in key that fits the lock) number. You could have an array of possible keys for locks as just that data member.

These wheels have already been implemented a zillion times. Might as well use a tool that's supposedly been debugged. But when new the feeling is to do things yourself to learn. Nothing wrong with that. :)

Edited by MilesAhead
Link to comment
Share on other sites

Hey again, folks! I really appreciate all your input - I love seeing how many different ways there are to go about the same thing.

However, now I have another question - I have heard a bit about GUI scripting, and I'd like to look into that a bit. How would I change my script so that instead of a popup (using InputBox) followed by a MsgBox, I had one nice window with a button and a place for the user to type their search query?

For reference, here is how my script is looking now (after all your awesome input yesterday). Ideally, I'd like to eventually have everything on one nice GUI instead of dealing with a hundred different MsgBoxes.

#cs -----------------------------------------------------------------------------------------------

Key Lookup Utility, version 1.7 BETA
Author: Dain Schroeder
Purpose: To make it easier to determine what key is needed for a specific rack
Started: October 20, 2012

#ce -----------------------------------------------------------------------------------------------

;First, because this script uses functions, we need to declare our variables as global.
Global $rack = 0
Global $key = 0
Global $version = "v1.8b"

;This 'While' statement contains the heart of the script, and forces it to loop forever
;(because I've told it to loop as long as 1 equals 1 - which is forever).
While 1 = 1
GetRack()
GiveKey()
Wend

;The GetRack function is the initial popup which asks what rack we want to lookup.
Func GetRack()
Do
$rack = InputBox("Dain's Key Lookup Utility " & $version, "Please enter the rack that you need to get into. This utility will then tell you which key opens that rack. You can also look up specific property names (but please note that feature is in progress and still experimental).", "Type a rack in the format 'CO1 AB123'", " M9")
If @error Then
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Thanks for using Dain's Key Lookup Utility. If you encountered any bugs, please report them to MY WORK EMAIL.")
Exit
Else
$validate = (StringLen($rack) > 1)
If Not $validate Then MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Oops - looks like you left the box empty. Please try again, or press Cancel to quit.")
EndIf
Until $validate
EndFunc

;The GiveKey function is where we check what key is needed and inform the user.
Func GiveKey()
;Alright, so now we know which rack the user needs to locate the key for. Now let's
;get to the real heart of this utility and figure out which key they need. We'll do this
;by using AutoIT's powerful "case" command. Every time the $rack variable we've declared
;globally is changed, the Case command will check if $rack matches a rack that the utility
;recognizes. If so, we'll inform the user what key they need. If not, the error is handled.
Switch $rack
Case "CO1 AM123", "CO1 AM124"
$key = "209 or 210"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR111"
$key = "171"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN102", "CO1 DN103"
$key = "133 or 134"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
Case "CO1 DN111"
$key = "142 or 143"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DR102", "CO1 DR103", "CO1 DR104", "CO1 DR105", "CO1 DR106", "CO1 DR107", "CO1 DR108", "CO1 DR109"
$key = "150 or 151"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN109"
$key = "271 or 272"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN110"
$key = "120 or 121"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN107", "CO1 DN108", "CO1 DJ425", "CO1 DJ426"
$key = "269 or 270"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AL218"
$key = "261 or 262"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AL217"
$key = "184 or 185"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD217", "CO1 AD218", "CO1 AD219", "CO1 AD220", "CO1 AD221", "CO1 AD222", "CO1 AD223", "CO1 AD224", "CO1 AD225", "CO1 AD226", "CO1 BQ202", "CO1 BQ203", "CO1 BQ204", "CO1 BQ205", "CO1 BQ206", "CO1 BQ207", "CO1 BQ208", "CO1 BQ209", "CO1 BQ210", "CO1 BQ211"
$key = "129 or 130"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP218", "CO1 AP219", "CO1 AP220", "CO1 AP221"
$key = "152 or 153"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR321"
$key = "136 or 137"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR322", "CO1 AW322", "CO1 AW323"
$key = "138 or 139"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR323", "CO1 AR324"
$key = "140 or 141"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR325", "CO1 AR326"
$key = "146 or 147"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR317", "CO1 AR318", "CO1 AR319", "CO1 AR320"
$key = "267 or 268"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AH317", "CO1 AH318", "CO1 AH319", "CO1 AH320", "CO1 AH321", "CO1 AH322", "CO1 AH323", "CO1 AM317", "CO1 AM318", "CO1 AM319", "CO1 AM320", "CO1 AM321", "CO1 AM322", "CO1 AM323", "CO1 CX310", "CO1 CX311", "CO1 DH308", "CO1 DH309", "CO1 DM306", "CO1 DM307", "CO1 DM308", "CO1 DM309", "CO1 DM310", "CO1 DM311"
$key = "257 or 258"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 BQ303"
$key = "216 or 217"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD317", "CO1 AD318", "CO1 AD319", "CO1 AD320", "CO1 AD321", "CO1 AD322", "CO1 AD323", "CO1 AD324", "CO1 AD325", "CO1 AD326", "CO1 AH324", "CO1 AH325", "CO1 AH326", "CO1 AM302", "CO1 AM303", "CO1 AM304", "CO1 AM305", "CO1 AM306", "CO1 AM307", "CO1 AM308", "CO1 AM309", "CO1 AM310", "CO1 AM311", "CO1 AM324", "CO1 AM325", "CO1 AM326", "CO1 AR302", "CO1 AR303", "CO1 AR309", "CO1 AR310", "CO1 AR311", "CO1 AW302", "CO1 AW303", "CO1 AW304", "CO1 AW305", "CO1 AW307", "CO1 AW308", "CO1 AW309", "CO1 AW311", "CO1 BB302", "CO1 BB303", "CO1 BB304", "CO1 BB305", "CO1 BB306", "CO1 BB307", "CO1 BB308", "CO1 BB310", "CO1 BB311", "CO1 BB318", "CO1 BB319", "CO1 BB320", "CO1 BB321", "CO1 BB322", "CO1 BB323", "CO1 BG302", "CO1 BG303", "CO1 BG304", "CO1 BG305", "CO1 BG306", "CO1 BG307", "CO1 BG308", "CO1 BG309", "CO1 BG310", "CO1 BG311", "CO1 BL302", "CO1 BL303", "CO1 BL304", "CO1 BL305", "CO1 BL306", "CO1 BL307", "CO1 BL308", "CO1 BL309", "CO1 BL310", "CO1 BL311", "CO1 BL312", "CO1 BL313", "CO1 BL314", "CO1 BL315", "CO1 BL316", "CO1 BQ304", "CO1 BQ305", "CO1 BQ306", "CO1 BQ307", "CO1 BQ308", "CO1 BQ309", "CO1 BQ310", "CO1 BQ311", "CO1 BQ312", "CO1 BQ313", "CO1 BQ314", "CO1 BQ315", "CO1 BQ316", "CO1 BU302", "CO1 BU303", "CO1 BU304", "CO1 BU305", "CO1 BU306", "CO1 BU307", "CO1 BU308", "CO1 BU309", "CO1 BU310", "CO1 BU311", "CO1 BU312", "CO1 BU313", "CO1 BU314", "CO1 BU315", "CO1 CI302", "CO1 CI303", "CO1 CI307", "CO1 CI308", "CO1 CI310", "CO1 CI311", "CO1 CI312", "CO1 CI313", "CO1 CI315", "CO1 CI316", "CO1 CI317", "CO1 CI319", "CO1 CI320", "CO1 CI321", "CO1 CI322", "CO1 CI323", "CO1 CI324", "CO1 CI325", "CO1 CN302", "CO1 CN303", "CO1 CN317", "CO1 CN318", "CO1 CN319", "CO1 CN320", "CO1 CS302", "CO1 CS303", "CO1 CX302", "CO1 CX303", "CO1 CX310", "CO1 CX311", "CO1 DC302", "CO1 DC303", "CO1 DC306", "CO1 DC307", "CO1 DC319", "CO1 DC323", "CO1 DC324", "CO1 DH302", "CO1 DH303", "CO1 DH304", "CO1 DH305", "CO1 DH306", "CO1 DH307", "CO1 DM302", "CO1 DM303", "CO1 DM304", "CO1 DM305", "CO1 DR302", "CO1 DR303", "CO1 DR304", "CO1 DR305", "CO1 DR306", "CO1 DR307", "CO1 DR308", "CO1 DR309"
$key = "199, 200, 201, or 202"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP222", "CO1 AP223", "CO1 AP224", "CO1 AP225", "CO1 AP226"
$key = "236 or 237"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AW317", "CO1 AW318", "CO1 AW319", "CO1 AW320", "CO1 AW321"
$key = "238 or 239"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AC303", "CO1 AC305", "CO1 AR305", "CO1 AR306", "CO1 AR307", "CO1 AR308", "CO1 AW310", "CO1 BQ302", "CO1 CN307", "CO1 CN310", "CO1 AH217", "CO1 AH218", "CO1 AH219", "CO1 AH220", "CO1 AH221", "CO1 AH222", "CO1 AH223", "CO1 AH224", "CO1 AH225", "CO1 AH226", "CO1 AL223", "CO1 AL224", "CO1 AL225", "CO1 AL226", "CO1 AY221", "CO1 AY222", "CO1 AY223", "CO1 AY224", "CO1 AY225", "CO1 AY226"
$key = "240 or 241"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD404", "CO1 AD405", "CO1 AD406", "CO1 AD407", "CO1 AD408", "CO1 AD409", "CO1 AD410", "CO1 DJ421", "CO1 DJ422", "CO1 DJ423", "CO1 DJ424", "CO1 DN417", "CO1 DN418", "CO1 DN419", "CO1 DN421", "CO1 DN422", "CO1 DN423", "CO1 DN424", "CO1 DN425", "CO1 DN426", "CO1 DR417", "CO1 DR418", "CO1 DR419", "CO1 DR420", "CO1 DR421", "CO1 DR422", "CO1 DR423", "CO1 DR424", "CO1 DR425", "CO1 DR426", "CO1 DN503", "CO1 DN504", "CO1 DN505", "CO1 DN506"
$key = "242 or 243"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DC319"
$key = "144 or 145"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD402", "CO1 AD403"
$key = "176 or 177"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD411"
$key = "178"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 BL422", "CO1 BL423", "CO1 BL425"
$key = "122 or 123"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 BL424", "CO1 BL426"
$key = "193 or 194"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP517"
$key = "118 or 119"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP518", "CO1 AP519"
$key = "263 or 264"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD517", "CO1 AD518", "CO1 AD519", "CO1 AD520", "CO1 AD521", "CO1 AD522", "CO1 AD523", "CO1 AD524", "CO1 AD525", "CO1 AH517", "CO1 AH518", "CO1 AH519", "CO1 AH520", "CO1 AH521", "CO1 AH522", "CO1 AH523", "CO1 AH524", "CO1 AH525", "CO1 AH526", "CO1 AL517", "CO1 AL518", "CO1 AL519", "CO1 AL520", "CO1 AL521", "CO1 AL522", "CO1 AL523", "CO1 AL524", "CO1 AL525", "CO1 AL526"
$key = "131 or 132"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AL219", "CO1 AL220", "CO1 AL221", "CO1 AL222", "CO2 AR116", "CO2 AR117", "CO2 AR118", "CO2 AR119"
$key = "222 or 223"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO2 AD103", "CO2 AD104", "CO2 AD105", "CO2 AD106", "CO2 AD107", "CO2 AD108", "CO2 AD109", "CO2 AD110", "CO2 AD111", "CO2 AD112", "CO2 AD113", "CO2 AD114"
$key = "265 or 266"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO2 AW103", "CO2 AW104", "CO2 AW105", "CO2 AW106", "CO2 AW107", "CO2 AW108", "CO2 AW109", "CO2 AW110", "CO2 DR203", "CO2 DR204", "CO2 DR205", "CO2 DR206", "CO2 DR207", "CO2 DR208", "CO2 DR209", "CO2 DR210", "CO2 DR211"
$key = "164, 165, or 166"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO2 AH315", "CO2 AH316", "CO2 AH317", "CO2 AH319", "CO2 AH320", "CO2 AH321", "CO2 AH322", "CO2 AH324", "CO2 AH325"
$key = "214 or 215"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
Case "CO2 BB312", "CO2 BB313", "CO2 BB315", "CO2 BB316", "CO2 BB317"
$key = "220 or 221"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
;From here on, I've added a few cases so that the user can type the names of different properties to quickly look up their keys.
Case "BPOS-S"
$key = "199, 200, 201, or 202"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "FOPE"
$key = "240 or 241"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "CTP"
$key = "131 or 132"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "BPOS-D"
$key = "257 or 258"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "MS Store"
$key = "152 or 153"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "Lync"
$key = "236 or 237"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case Else
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Sorry, '" & $rack & "' does not appear to be a recognized rack. If you are certain this rack exists but is not yet recognized by this program, please send a bug report to MY WORK EMAIL.")
EndSwitch
EndFunc
Link to comment
Share on other sites

Global $rack, $key, $version = "v1.8b"

$hGui = GUICreate("Dain's Key Lookup Utility " & $version, 650, 160)
$iInput = GUICtrlCreateLabel("Please enter the rack that you need to get into. This utility will then tell you which key opens that rack. You can also look up specific property names (but please note that feature is in progress and still experimental).", 10, 10, 600, 34)
$iInput = GUICtrlCreateInput("Type a rack in the format 'CO1 AB123'", 10, 50, 220, 22)
$iButton = GUICtrlCreateButton('Get', 10, 80, 120, 28)
$iStatusBar = GUICtrlCreateLabel('StatusBar', 5, 160 - 20, 600, 17)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $iButton
            $rack = GUICtrlRead($iInput)
            $validate = (StringLen($rack) > 1)
            If Not $validate Then
                _SetData("Oops - looks like you left the box empty. Please try again, or press Cancel to quit.")
                ; GUICtrlSetData($iStatusBar, "Oops - looks like you left the box empty. Please try again, or press Cancel to quit.")
                ContinueLoop
            Else
                $answer = GiveKey()
                _SetData($answer[0] & ', ' & $answer[1])
                ; GUICtrlSetData($iStatusBar, $answer[0] & ', ' & $answer[1])
            EndIf
        Case -3
            ; MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Thanks for using Dain's Key Lookup Utility. If you encountered any bugs, please report them to MY WORK EMAIL.")
            Exit
    EndSwitch
WEnd

Func _SetData($Data)
    GUICtrlSetData($iStatusBar, $Data)
    $trOper=1
    For $i = 1 to 4
        GUICtrlSetBkColor ($iStatusBar, 0xff0000 )
        GUICtrlSetColor ($iStatusBar, 0xffffff)
        Sleep(40)
        GUICtrlSetBkColor ($iStatusBar, -1 )
        GUICtrlSetColor ($iStatusBar, 0xff0000)
        Sleep(40)
    Next
EndFunc

Func GiveKey()
    Local $answer[2]
    Switch $rack
        Case "CO1 AM123", "CO1 AM124"
            $key = "209 or 210"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AR111"
            $key = "171"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 DN102", "CO1 DN103"
            $key = "133 or 134"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only."
        Case "CO1 DN111"
            $key = "142 or 143"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 DR102", "CO1 DR103", "CO1 DR104", "CO1 DR105", "CO1 DR106", "CO1 DR107", "CO1 DR108", "CO1 DR109"
            $key = "150 or 151"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 DN109"
            $key = "271 or 272"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 DN110"
            $key = "120 or 121"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 DN107", "CO1 DN108", "CO1 DJ425", "CO1 DJ426"
            $key = "269 or 270"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AL218"
            $key = "261 or 262"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AL217"
            $key = "184 or 185"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AD217", "CO1 AD218", "CO1 AD219", "CO1 AD220", "CO1 AD221", "CO1 AD222", "CO1 AD223", "CO1 AD224", "CO1 AD225", "CO1 AD226", "CO1 BQ202", "CO1 BQ203", "CO1 BQ204", "CO1 BQ205", "CO1 BQ206", "CO1 BQ207", "CO1 BQ208", "CO1 BQ209", "CO1 BQ210", "CO1 BQ211"
            $key = "129 or 130"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AP218", "CO1 AP219", "CO1 AP220", "CO1 AP221"
            $key = "152 or 153"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AR321"
            $key = "136 or 137"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AR322", "CO1 AW322", "CO1 AW323"
            $key = "138 or 139"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AR323", "CO1 AR324"
            $key = "140 or 141"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AR325", "CO1 AR326"
            $key = "146 or 147"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AR317", "CO1 AR318", "CO1 AR319", "CO1 AR320"
            $key = "267 or 268"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AH317", "CO1 AH318", "CO1 AH319", "CO1 AH320", "CO1 AH321", "CO1 AH322", "CO1 AH323", "CO1 AM317", "CO1 AM318", "CO1 AM319", "CO1 AM320", "CO1 AM321", "CO1 AM322", "CO1 AM323", "CO1 CX310", "CO1 CX311", "CO1 DH308", "CO1 DH309", "CO1 DM306", "CO1 DM307", "CO1 DM308", "CO1 DM309", "CO1 DM310", "CO1 DM311"
            $key = "257 or 258"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 BQ303"
            $key = "216 or 217"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AD317", "CO1 AD318", "CO1 AD319", "CO1 AD320", "CO1 AD321", "CO1 AD322", "CO1 AD323", "CO1 AD324", "CO1 AD325", "CO1 AD326", "CO1 AH324", "CO1 AH325", "CO1 AH326", "CO1 AM302", "CO1 AM303", "CO1 AM304", "CO1 AM305", "CO1 AM306", "CO1 AM307", "CO1 AM308", "CO1 AM309", "CO1 AM310", "CO1 AM311", "CO1 AM324", "CO1 AM325", "CO1 AM326", "CO1 AR302", "CO1 AR303", "CO1 AR309", "CO1 AR310", "CO1 AR311", "CO1 AW302", "CO1 AW303", "CO1 AW304", "CO1 AW305", "CO1 AW307", "CO1 AW308", "CO1 AW309", "CO1 AW311", "CO1 BB302", "CO1 BB303", "CO1 BB304", "CO1 BB305", "CO1 BB306", "CO1 BB307", "CO1 BB308", "CO1 BB310", "CO1 BB311", "CO1 BB318", "CO1 BB319", "CO1 BB320", "CO1 BB321", "CO1 BB322", "CO1 BB323", "CO1 BG302", "CO1 BG303", "CO1 BG304", "CO1 BG305", "CO1 BG306", "CO1 BG307", "CO1 BG308", "CO1 BG309", "CO1 BG310", "CO1 BG311", "CO1 BL302", "CO1 BL303", "CO1 BL304", "CO1 BL305", "CO1 BL306", "CO1 BL307", "CO1 BL308", "CO1 BL309", "CO1 BL310", "CO1 BL311", "CO1 BL312", "CO1 BL313", "CO1 BL314", "CO1 BL315", "CO1 BL316", "CO1 BQ304", "CO1 BQ305", "CO1 BQ306", "CO1 BQ307", "CO1 BQ308", "CO1 BQ309", "CO1 BQ310", "CO1 BQ311", "CO1 BQ312", "CO1 BQ313", "CO1 BQ314", "CO1 BQ315", "CO1 BQ316", "CO1 BU302", "CO1 BU303", "CO1 BU304", "CO1 BU305", "CO1 BU306", "CO1 BU307", "CO1 BU308", "CO1 BU309", "CO1 BU310", "CO1 BU311", "CO1 BU312", "CO1 BU313", "CO1 BU314", "CO1 BU315", "CO1 CI302", "CO1 CI303", "CO1 CI307", "CO1 CI308", "CO1 CI310", "CO1 CI311", "CO1 CI312", "CO1 CI313", "CO1 CI315", "CO1 CI316", "CO1 CI317", "CO1 CI319", "CO1 CI320", "CO1 CI321", "CO1 CI322", "CO1 CI323", "CO1 CI324", "CO1 CI325", "CO1 CN302", "CO1 CN303", "CO1 CN317", "CO1 CN318", "CO1 CN319", "CO1 CN320", "CO1 CS302", "CO1 CS303", "CO1 CX302", "CO1 CX303", "CO1 CX310", "CO1 CX311", "CO1 DC302", "CO1 DC303", "CO1 DC306", "CO1 DC307", "CO1 DC319", "CO1 DC323", "CO1 DC324", "CO1 DH302", "CO1 DH303", "CO1 DH304", "CO1 DH305", "CO1 DH306", "CO1 DH307", "CO1 DM302", "CO1 DM303", "CO1 DM304", "CO1 DM305", "CO1 DR302", "CO1 DR303", "CO1 DR304", "CO1 DR305", "CO1 DR306", "CO1 DR307", "CO1 DR308", "CO1 DR309"
            $key = "199, 200, 201, or 202"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AP222", "CO1 AP223", "CO1 AP224", "CO1 AP225", "CO1 AP226"
            $key = "236 or 237"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AW317", "CO1 AW318", "CO1 AW319", "CO1 AW320", "CO1 AW321"
            $key = "238 or 239"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AC303", "CO1 AC305", "CO1 AR305", "CO1 AR306", "CO1 AR307", "CO1 AR308", "CO1 AW310", "CO1 BQ302", "CO1 CN307", "CO1 CN310", "CO1 AH217", "CO1 AH218", "CO1 AH219", "CO1 AH220", "CO1 AH221", "CO1 AH222", "CO1 AH223", "CO1 AH224", "CO1 AH225", "CO1 AH226", "CO1 AL223", "CO1 AL224", "CO1 AL225", "CO1 AL226", "CO1 AY221", "CO1 AY222", "CO1 AY223", "CO1 AY224", "CO1 AY225", "CO1 AY226"
            $key = "240 or 241"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AD404", "CO1 AD405", "CO1 AD406", "CO1 AD407", "CO1 AD408", "CO1 AD409", "CO1 AD410", "CO1 DJ421", "CO1 DJ422", "CO1 DJ423", "CO1 DJ424", "CO1 DN417", "CO1 DN418", "CO1 DN419", "CO1 DN421", "CO1 DN422", "CO1 DN423", "CO1 DN424", "CO1 DN425", "CO1 DN426", "CO1 DR417", "CO1 DR418", "CO1 DR419", "CO1 DR420", "CO1 DR421", "CO1 DR422", "CO1 DR423", "CO1 DR424", "CO1 DR425", "CO1 DR426", "CO1 DN503", "CO1 DN504", "CO1 DN505", "CO1 DN506"
            $key = "242 or 243"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 DC319"
            $key = "144 or 145"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AD402", "CO1 AD403"
            $key = "176 or 177"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AD411"
            $key = "178"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 BL422", "CO1 BL423", "CO1 BL425"
            $key = "122 or 123"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 BL424", "CO1 BL426"
            $key = "193 or 194"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AP517"
            $key = "118 or 119"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AP518", "CO1 AP519"
            $key = "263 or 264"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AD517", "CO1 AD518", "CO1 AD519", "CO1 AD520", "CO1 AD521", "CO1 AD522", "CO1 AD523", "CO1 AD524", "CO1 AD525", "CO1 AH517", "CO1 AH518", "CO1 AH519", "CO1 AH520", "CO1 AH521", "CO1 AH522", "CO1 AH523", "CO1 AH524", "CO1 AH525", "CO1 AH526", "CO1 AL517", "CO1 AL518", "CO1 AL519", "CO1 AL520", "CO1 AL521", "CO1 AL522", "CO1 AL523", "CO1 AL524", "CO1 AL525", "CO1 AL526"
            $key = "131 or 132"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO1 AL219", "CO1 AL220", "CO1 AL221", "CO1 AL222", "CO2 AR116", "CO2 AR117", "CO2 AR118", "CO2 AR119"
            $key = "222 or 223"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO2 AD103", "CO2 AD104", "CO2 AD105", "CO2 AD106", "CO2 AD107", "CO2 AD108", "CO2 AD109", "CO2 AD110", "CO2 AD111", "CO2 AD112", "CO2 AD113", "CO2 AD114"
            $key = "265 or 266"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO2 AW103", "CO2 AW104", "CO2 AW105", "CO2 AW106", "CO2 AW107", "CO2 AW108", "CO2 AW109", "CO2 AW110", "CO2 DR203", "CO2 DR204", "CO2 DR205", "CO2 DR206", "CO2 DR207", "CO2 DR208", "CO2 DR209", "CO2 DR210", "CO2 DR211"
            $key = "164, 165, or 166"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "!"
        Case "CO2 AH315", "CO2 AH316", "CO2 AH317", "CO2 AH319", "CO2 AH320", "CO2 AH321", "CO2 AH322", "CO2 AH324", "CO2 AH325"
            $key = "214 or 215"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only."
        Case "CO2 BB312", "CO2 BB313", "CO2 BB315", "CO2 BB316", "CO2 BB317"
            $key = "220 or 221"
            $msg = "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only."
            ;From here on, I've added a few cases so that the user can type the names of different properties to quickly look up their keys.
        Case "BPOS-S"
            $key = "199, 200, 201, or 202"
            $msg = "To open the racks for the property " & $rack & ", you need key number " & $key & "!"
        Case "FOPE"
            $key = "240 or 241"
            $msg = "To open the racks for the property " & $rack & ", you need key number " & $key & "!"
        Case "CTP"
            $key = "131 or 132"
            $msg = "To open the racks for the property " & $rack & ", you need key number " & $key & "!"
        Case "BPOS-D"
            $key = "257 or 258"
            $msg = "To open the racks for the property " & $rack & ", you need key number " & $key & "!"
        Case "MS Store"
            $key = "152 or 153"
            $msg = "To open the racks for the property " & $rack & ", you need key number " & $key & "!"
        Case "Lync"
            $key = "236 or 237"
            $msg = "To open the racks for the property " & $rack & ", you need key number " & $key & "!"
        Case Else
            $key = "- // - "
            $msg = "Sorry, '" & $rack & "' does not appear to be a recognized rack. If you are certain this rack exists but is not yet recognized by this program, please send a bug report to MY WORK EMAIL."
    EndSwitch
    $answer[0] = $key
    $answer[1] = $msg
    Return $answer
EndFunc

Edited by AZJIO
Link to comment
Share on other sites

AZJIO, thank you *very* much for going "above and beyond" there. Your post actually gives me deep insight into how GUI works in AutoIT, and I'll enjoy playing around with it to tweak it to my (very perfectionist) liking.

Other than "liking" a person's post, is there some other way on this forum to formally thank someone?

Link to comment
Share on other sites

How would I change my script so that instead of a popup (using InputBox) followed by a MsgBox, I had one nice window with a button and a place for the user to type their search query?

Did you try running post #6?

I wouldn't consider Switch/Case suitable for such a large number of data combinations.

All those hard-coded values will be a maintenance nightmare and require program recompiles any time a change is made.

I'd suggest looking into loading arrays from an external file that can be easily updated without needing to recompile your program.

Link to comment
Share on other sites

Did you try running post #6?

I wouldn't consider Switch/Case suitable for such a large number of data combinations.

All those hard-coded values will be a maintenance nightmare and require program recompiles any time a change is made.

I'd suggest looking into loading arrays from an external file that can be easily updated without needing to recompile your program.

I actually did toy with your script quite a bit - while tumblers don't really apply here, your script is awesome and I certainly see some advantages to it. If I wanted to do something similar to what you posted, but with a search box instead of a drop-down box to search for keys, how would I go about it?

Link to comment
Share on other sites

tumblers don't really apply

a search box instead of a drop-down box to search for keys, how would I go about it?

Lock, tumbler, I didnt really know what to call it, but that seems your unique, base unit to keep track of.

Multiple locations can have the same lock? So locations aren't unique..

Multiple keys can fit the same lock, so keys aren't unique.

So the three tables still make sense to me, not that you need to store the little engraved codes (if the locks have them) or display them to the user. If you aren't going to store or display that then just a variable like $iDifferentLocks =12 could replace the tumblers table, and then point the values in the location and keys tables to the corresponding lock number. I really don't know your exact sutuation, but this is what seems the way I'd go.

Look at using GUICtrlCreateInput() instead of GUICtrlCreateCombo().

Link to comment
Share on other sites

  • 1 month later...

Hello again, everyone! I had another question with this same script (though it's now evolved much, much further). I am still using the "case" method that I was previously using, with a msgbox then being returned containing the value of $key. But what if I want the user to be able to type in a key number, and have it return the list of locks that key can open? (In other words, the exact opposite of what the program currently does - but hopefully without me having to just make twice the "case" statements.)

Here's how the script looks right now (slightly modified to remove all data that is protected by non-disclosure agreement).

#cs -----------------------------------------------------------------------------------------------

Key Lookup Utility, version 1.9F BETA
Author: Dain Schroeder
Purpose: To make it easier to determine what key is needed for a specific rack
Started: October 20, 2012

#ce -----------------------------------------------------------------------------------------------

;First, because this script uses functions, we need to declare our variables as global.
Global $rack = 0
Global $key = 0
Global $version = "v1.9f"
Global $leprechaun = "evil" ;used for secret "Leprechaun mode" feature.

;This 'While' statement contains the heart of the script, and forces it to loop forever
;(because I've told it to loop as long as 1 equals 1 - which is forever).
While 1 = 1
GetRack()
GiveKey()
Wend

;The GetRack function is the initial popup which asks what rack we want to lookup.
Func GetRack()
Do
$rack = InputBox("Dain's Key Lookup Utility " & $version, "Please enter the rack that you need to get into. This utility will then tell you which key opens that rack. You can also search by property name.", "Type a rack in the format 'CO1 AB123'", " M10")
If @error Then
;MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Thanks for using Dain's Key Lookup Utility. If you encountered any bugs, please report them to MY WORK EMAIL")
Exit
Else
$validate = (StringLen($rack) > 1)
If Not $validate Then MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Oops - looks like you left the box empty. Please try again, or press Cancel to quit.")
EndIf
Until $validate
EndFunc

;The GiveKey function is where we check what key is needed and inform the user.
Func GiveKey()
;Alright, so now we know which rack the user needs to locate the key for. Now let's
;get to the real heart of this utility and figure out which key they need. We'll do this
;by using AutoIT's powerful "case" command. Every time the $rack variable we've declared
;globally is changed, the Case command will check if $rack matches a rack that the utility
;recognizes. If so, we'll inform the user what key they need. If not, the error is handled.
Switch $rack
Case "CO1 AM123", "CO1 AM124"
$key = "209 or 210"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR111"
$key = "171"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN102", "CO1 DN103"
$key = "133 or 134"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
Case "CO1 DN111"
$key = "142 or 143"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DR102", "CO1 DR103", "CO1 DR104", "CO1 DR105", "CO1 DR106", "CO1 DR107", "CO1 DR108", "CO1 DR109"
$key = "150 or 151"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN109"
$key = "271 or 272"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN110"
$key = "120 or 121"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DN107", "CO1 DN108", "CO1 DJ425", "CO1 DJ426"
$key = "269 or 270"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AL218"
$key = "261 or 262"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AL217"
$key = "184 or 185"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD217", "CO1 AD218", "CO1 AD219", "CO1 AD220", "CO1 AD221", "CO1 AD222", "CO1 AD223", "CO1 AD224", "CO1 AD225", "CO1 AD226", "CO1 BQ202", "CO1 BQ203", "CO1 BQ204", "CO1 BQ205", "CO1 BQ206", "CO1 BQ207", "CO1 BQ208", "CO1 BQ209", "CO1 BQ210", "CO1 BQ211"
$key = "129 or 130"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP218", "CO1 AP219", "CO1 AP220", "CO1 AP221"
$key = "152 or 153"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR321"
$key = "136 or 137"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR322", "CO1 AW322", "CO1 AW323"
$key = "138 or 139"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR323", "CO1 AR324"
$key = "140 or 141"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR325", "CO1 AR326"
$key = "146 or 147"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AR317", "CO1 AR318", "CO1 AR319", "CO1 AR320"
$key = "267 or 268"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AH317", "CO1 AH318", "CO1 AH319", "CO1 AH320", "CO1 AH321", "CO1 AH322", "CO1 AH323", "CO1 AM317", "CO1 AM318", "CO1 AM319", "CO1 AM320", "CO1 AM321", "CO1 AM322", "CO1 AM323", "CO1 CX310", "CO1 CX311", "CO1 DH308", "CO1 DH309", "CO1 DM306", "CO1 DM307", "CO1 DM308", "CO1 DM309", "CO1 DM310", "CO1 DM311"
$key = "257 or 258"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 BQ303"
$key = "216 or 217"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD317", "CO1 AD318", "CO1 AD319", "CO1 AD320", "CO1 AD321", "CO1 AD322", "CO1 AD323", "CO1 AD324", "CO1 AD325", "CO1 AD326", "CO1 AH324", "CO1 AH325", "CO1 AH326", "CO1 AM302", "CO1 AM303", "CO1 AM304", "CO1 AM305", "CO1 AM306", "CO1 AM307", "CO1 AM308", "CO1 AM309", "CO1 AM310", "CO1 AM311", "CO1 AM324", "CO1 AM325", "CO1 AM326", "CO1 AR302", "CO1 AR303", "CO1 AR309", "CO1 AR310", "CO1 AR311", "CO1 AW302", "CO1 AW303", "CO1 AW304", "CO1 AW305", "CO1 AW307", "CO1 AW308", "CO1 AW309", "CO1 AW311", "CO1 BB302", "CO1 BB303", "CO1 BB304", "CO1 BB305", "CO1 BB306", "CO1 BB307", "CO1 BB308", "CO1 BB310", "CO1 BB311", "CO1 BB318", "CO1 BB319", "CO1 BB320", "CO1 BB321", "CO1 BB322", "CO1 BB323", "CO1 BG302", "CO1 BG303", "CO1 BG304", "CO1 BG305", "CO1 BG306", "CO1 BG307", "CO1 BG308", "CO1 BG309", "CO1 BG310", "CO1 BG311", "CO1 BL302", "CO1 BL303", "CO1 BL304", "CO1 BL305", "CO1 BL306", "CO1 BL307", "CO1 BL308", "CO1 BL309", "CO1 BL310", "CO1 BL311", "CO1 BL312", "CO1 BL313", "CO1 BL314", "CO1 BL315", "CO1 BL316", "CO1 BQ304", "CO1 BQ305", "CO1 BQ306", "CO1 BQ307", "CO1 BQ308", "CO1 BQ309", "CO1 BQ310", "CO1 BQ311", "CO1 BQ312", "CO1 BQ313", "CO1 BQ314", "CO1 BQ315", "CO1 BQ316", "CO1 BU302", "CO1 BU303", "CO1 BU304", "CO1 BU305", "CO1 BU306", "CO1 BU307", "CO1 BU308", "CO1 BU309", "CO1 BU310", "CO1 BU311", "CO1 BU312", "CO1 BU313", "CO1 BU314", "CO1 BU315", "CO1 CI302", "CO1 CI303", "CO1 CI307", "CO1 CI308", "CO1 CI310", "CO1 CI311", "CO1 CI312", "CO1 CI313", "CO1 CI315", "CO1 CI316", "CO1 CI317", "CO1 CI319", "CO1 CI320", "CO1 CI321", "CO1 CI322", "CO1 CI323", "CO1 CI324", "CO1 CI325", "CO1 CN302", "CO1 CN303", "CO1 CN317", "CO1 CN318", "CO1 CN319", "CO1 CN320", "CO1 CS302", "CO1 CS303", "CO1 CX302", "CO1 CX303", "CO1 CX310", "CO1 CX311", "CO1 DC302", "CO1 DC303", "CO1 DC306", "CO1 DC307", "CO1 DC319", "CO1 DC323", "CO1 DC324", "CO1 DH302", "CO1 DH303", "CO1 DH304", "CO1 DH305", "CO1 DH306", "CO1 DH307", "CO1 DM302", "CO1 DM303", "CO1 DM304", "CO1 DM305", "CO1 DR302", "CO1 DR303", "CO1 DR304", "CO1 DR305", "CO1 DR306", "CO1 DR307", "CO1 DR308", "CO1 DR309"
$key = "199, 200, 201, or 202"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP222", "CO1 AP223", "CO1 AP224", "CO1 AP225", "CO1 AP226"
$key = "236 or 237"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AW317", "CO1 AW318", "CO1 AW319", "CO1 AW320", "CO1 AW321"
$key = "238 or 239"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AC303", "CO1 AC305", "CO1 AR305", "CO1 AR306", "CO1 AR307", "CO1 AR308", "CO1 AW310", "CO1 BQ302", "CO1 CN307", "CO1 CN310", "CO1 AH217", "CO1 AH218", "CO1 AH219", "CO1 AH220", "CO1 AH221", "CO1 AH222", "CO1 AH223", "CO1 AH224", "CO1 AH225", "CO1 AH226", "CO1 AL223", "CO1 AL224", "CO1 AL225", "CO1 AL226", "CO1 AY221", "CO1 AY222", "CO1 AY223", "CO1 AY224", "CO1 AY225", "CO1 AY226"
$key = "240 or 241"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD404", "CO1 AD405", "CO1 AD406", "CO1 AD407", "CO1 AD408", "CO1 AD409", "CO1 AD410", "CO1 DJ421", "CO1 DJ422", "CO1 DJ423", "CO1 DJ424", "CO1 DN417", "CO1 DN418", "CO1 DN419", "CO1 DN421", "CO1 DN422", "CO1 DN423", "CO1 DN424", "CO1 DN425", "CO1 DN426", "CO1 DR417", "CO1 DR418", "CO1 DR419", "CO1 DR420", "CO1 DR421", "CO1 DR422", "CO1 DR423", "CO1 DR424", "CO1 DR425", "CO1 DR426", "CO1 DN503", "CO1 DN504", "CO1 DN505", "CO1 DN506"
$key = "242 or 243"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 DC319"
$key = "144 or 145"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD402", "CO1 AD403"
$key = "176 or 177"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD411"
$key = "178"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 BL422", "CO1 BL423", "CO1 BL425"
$key = "122 or 123"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 BL424", "CO1 BL426"
$key = "193 or 194"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP517"
$key = "118 or 119"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AP518", "CO1 AP519"
$key = "263 or 264"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD509", "CO1 AD510", "CO1 AD511", "CO1 AD517", "CO1 AD518", "CO1 AD519", "CO1 AD520", "CO1 AD521", "CO1 AD522", "CO1 AD523", "CO1 AD524", "CO1 AD525", "CO1 AD526", "CO1 AH509", "CO1 AH510", "CO1 AH511", "CO1 AH517", "CO1 AH518", "CO1 AH519", "CO1 AH520", "CO1 AH521", "CO1 AH522", "CO1 AH523", "CO1 AH524", "CO1 AH525", "CO1 AH526", "CO1 AL502", "CO1 AL503", "CO1 AL504", "CO1 AL505", "CO1 AL506", "CO1 AL507", "CO1 AL508", "CO1 AL509", "CO1 AL510", "CO1 AL511", "CO1 AL517", "CO1 AL518", "CO1 AL519", "CO1 AL520", "CO1 AL521", "CO1 AL522", "CO1 AL523", "CO1 AL524", "CO1 AL525", "CO1 AL526", "CO1 AP502", "CO1 AP503", "CO1 AP504", "CO1 AP505", "CO1 AP506", "CO1 AP507", "CO1 AP508", "CO1 AP509", "CO1 AP510", "CO1 AP511", "CO1 AP520", "CO1 AP521", "CO1 AP522", "CO1 AP523", "CO1 AP524", "CO1 AP525", "CO1 AP526", "CO1 AT502", "CO1 AT503", "CO1 AT504", "CO1 AT505", "CO1 AT506", "CO1 AT507", "CO1 AT508", "CO1 AT509", "CO1 AT510", "CO1 AT511", "CO1 AT517", "CO1 AT518", "CO1 AT519", "CO1 AT520", "CO1 AT521", "CO1 AT522", "CO1 AT523", "CO1 AT524", "CO1 AT525", "CO1 AT526", "CO1 BC509", "CO1 BC510", "CO1 BC511", "CO1 BH509", "CO1 BH510", "CO1 BH511"
$key = "131 or 132"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AD502", "CO1 AD503", "CO1 AD504", "CO1 AD505", "CO1 AD506", "CO1 AD507", "CO1 AD508", "CO1 AH502", "CO1 AH503", "CO1 AH504", "CO1 AH505", "CO1 AH506", "CO1 AH507", "CO1 AH508", "CO1 BC502", "CO1 BC503", "CO1 BC504", "CO1 BC505", "CO1 BC506", "CO1 BC507", "CO1 BC508", "CO1 BH502", "CO1 BH503", "CO1 BH504", "CO1 BH505", "CO1 BH506", "CO1 BH507", "CO1 BH508"
$key = "127 or 128"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO1 AL219", "CO1 AL220", "CO1 AL221", "CO1 AL222", "CO2 AR116", "CO2 AR117", "CO2 AR118", "CO2 AR119"
$key = "222 or 223"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO2 AD103", "CO2 AD104", "CO2 AD105", "CO2 AD106", "CO2 AD107", "CO2 AD108", "CO2 AD109", "CO2 AD110", "CO2 AD111", "CO2 AD112", "CO2 AD113", "CO2 AD114"
$key = "265 or 266"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO2 AW103", "CO2 AW104", "CO2 AW105", "CO2 AW106", "CO2 AW107", "CO2 AW108", "CO2 AW109", "CO2 AW110", "CO2 DR203", "CO2 DR204", "CO2 DR205", "CO2 DR206", "CO2 DR207", "CO2 DR208", "CO2 DR209", "CO2 DR210", "CO2 DR211"
$key = "164, 165, or 166"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "!")
Case "CO2 AH315", "CO2 AH316", "CO2 AH317", "CO2 AH319", "CO2 AH320", "CO2 AH321", "CO2 AH322", "CO2 AH324", "CO2 AH325"
$key = "214 or 215"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
Case "CO2 BB312", "CO2 BB313", "CO2 BB315", "CO2 BB316", "CO2 BB317"
$key = "220 or 221"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the rack " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
;From here on, I've added a few cases so that the user can type the names of different properties to quickly look up their keys.
Case "BPOS-S"
$key = "199, 200, 201, or 202"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "FOPE"
$key = "240 or 241"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "CTP"
$key = "131 or 132"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you'll usually need key number " & $key & ". There are also some CTP racks that need to be opened with key 127 or 128. Those racks are: CO1 AD502-AD508, CO1 AH502-AH508, CO1 BC502-BC508, and CO1 BH502-BH508.")
Case "BPOS-D"
$key = "257 or 258"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "MS Store"
$key = "152 or 153"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "Lync"
$key = "236 or 237"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "Xbox", "XBOX", "xbox"
$key = "154, 155, 156, 157, or 158"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "CPS", "Core Platform"
$key = "133 or 134"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "! Please note that these racks are for FTEs only.")
Case "MSODS"
$key = "242 or 243"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "SSG"
$key = "209 or 210"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "To open the racks for the property " & $rack & ", you need key number " & $key & "!")
Case "Leprechaun"
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Many years ago, an evil leprechaun terrorized the entire Security team by haunting the SOC every night. Some say he still haunts the SOC to this very day...")
Case Else
MsgBox(4096, "Dain's Key Lookup Utility " & $version, "Sorry, '" & $rack & "' does not appear to be a recognized rack or property. If you are certain this rack exists but is not yet recognized by this program, please send a bug report to MY WORK EMAIL.")
EndSwitch
EndFunc
Link to comment
Share on other sites

  • 5 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...