ksmith247 Posted June 29, 2007 Posted June 29, 2007 Script reads actual computer names from an ini file. This is to allow users to access a particular share on different PCs. I am wondering if the functions could be done another way. It just seems so cumbersome. expandcollapse popup#include <GuiConstants.au3> GUICreate("Scale Docs", 324, 160, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Combo_1 = GUICtrlCreateCombo("Primaries", 20, 40, 150, 21) GUICtrlSetData(-1, "---------|Ashtabula|Birmingham|Knoxville|Chattanooga|Macon|Linwood|Roanoke|Lambert's Point|Sheffield|Allentown|Conway|Elkhart") $Combo_2 = GUICtrlCreateCombo("Backups", 20, 90, 150, 21) GUICtrlSetData(-1, "---------|Ashtabula Backup|Birmingham Backup|Knoxville Backup|Chattanooga Backup|Macon Backup|Linwood Backup|Roanoke Backup|Lambert's Point Backup|Sheffield Backup|Allentown Backup|Conway Backup|Elkhart Backup") $Button_1 = GUICtrlCreateButton("&Primary", 230, 35, 70, 30) $Button_2 = GUICtrlCreateButton("&Backup", 230, 85, 70, 30) $Label_3 = GUICtrlCreateLabel("Primary Controllers", 40, 20, 90, 20) $Label_4 = GUICtrlCreateLabel("Backup Controllers", 40, 70, 90, 20) $helpmenu = GUICtrlCreateMenu("Help") $infoitem = GUICtrlCreateMenuitem("Info", $helpmenu) $ConfigFile = _GetConfigFile("Controllers.ini") GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else If $msg = $Button_1 Then _cName() EndIf If $msg = $Button_2 Then _Backups() EndIf If $msg = $infoitem Then MsgBox(0, "Scale Docs Help", "Select the site you wish to access from the dropdown list then click" _ & @CRLF & "the appropriate button. If you have any trouble, with this application," _ & @CRLF & "please call the helpdesk and have a ticket opened.") EndIf EndSelect WEnd Exit Func _GetConfigFile($filename, $silent = False) Local $configfilename $configfilename = @ScriptDir & "\" & $filename If Not FileExists($configfilename) Then If Not $silent Then MsgBox(16, "File Missing", "The file " & $filename & " is not available." & @CRLF & "Please ensure that it is located in the " & @ScriptDir & " directory." & @CRLF & "The application will now exit.") Exit EndIf SetError(1) Return "Error" EndIf Return $configfilename EndFunc ;==>_GetConfigFile Func _Backups() If GUICtrlRead($Combo_2) = "Ashtabula Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Ashtabula", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Birmingham Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Birmingham", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Knoxville Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Knoxville", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Chattanooga Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Chattanooga", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Macon Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Macon", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Linwood Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Linwood", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Roanoke Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Roanoke", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Lambert's Point Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Lambert's Point", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Sheffield Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Sheffield", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Allentown Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Allentown", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Conway Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Conway", "secondary", "") & "\c$") EndIf If GUICtrlRead($Combo_2) = "Knoxville Backup" Then ShellExecute("\\" & IniRead($ConfigFile, "Knoxville", "secondary", "") & "\c$") EndIf EndFunc ;==>_Backups Func _cName() If GUICtrlRead($Combo_1) = "Ashtabula" Then ShellExecute("\\" & IniRead($ConfigFile, "Ashtabula", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Birmingham" Then ShellExecute("\\" & IniRead($ConfigFile, "Birmingham", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Knoxville" Then ShellExecute("\\" & IniRead($ConfigFile, "Knoxville", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Chattanooga" Then ShellExecute("\\" & IniRead($ConfigFile, "Chattanooga", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Macon" Then ShellExecute("\\" & IniRead($ConfigFile, "Macon", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Linwood" Then ShellExecute("\\" & IniRead($ConfigFile, "Linwood", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Roanoke" Then ShellExecute("\\" & IniRead($ConfigFile, "Roanoke", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Lambert's Point" Then ShellExecute("\\" & IniRead($ConfigFile, "Lambert's Point", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Sheffield" Then ShellExecute("\\" & IniRead($ConfigFile, "Sheffield", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Allentown" Then ShellExecute("\\" & IniRead($ConfigFile, "Allentown", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Conway" Then ShellExecute("\\" & IniRead($ConfigFile, "Conway", "primary", "") & "\c$") EndIf If GUICtrlRead($Combo_1) = "Knoxville" Then ShellExecute("\\" & IniRead($ConfigFile, "Knoxville", "primary", "") & "\c$") EndIf EndFunc ;==>_cName Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]
Paulie Posted June 29, 2007 Posted June 29, 2007 (edited) You could redo the functions so each executes a for loop, and have all the names in a StringSplit, That would make the code smaller, but i don't know how to so whatever it is that you are doing with ShellExecute() more efficient. An example with your "_cName" function Global $Primaries = StringSplit("Ashtabula|Birmingham|Knoxville|Chattanooga|Macon|Linwood|Roanoke|Lambert's" & _ "Point|Sheffield|Allentown|Conway|Elkhart", "|") Func _cNames() For $i = 1 to $Primaries[0];Number of splits If GUICtrlRead($Combo_1) = $Primaries[$i] Then ShellExecute("\\" & IniRead($ConfigFile, $Primaries[$i], "primary", "") & "\c$") EndIf Next EndFunc Edited June 29, 2007 by Paulie
ksmith247 Posted June 29, 2007 Author Posted June 29, 2007 Thank you. I will try that. It certainly does shorten the script. Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now