gseller Posted May 24, 2007 Posted May 24, 2007 I am hoping someone can steer me in the right direction? I am trying to write a switchboard to launch hummingbird switches by reading an IP from an ini file and adding to a shellexecute to launch a telnet session. Here is my code: I put this together from the Helpfile expandcollapse popup#include <GUIConstants.au3> Dim $swt1, $swt2, $swt3 Dim $swt2 = 2, $swt3 = 10, $swt3 = 20 GUICreate("Switch Board", 200, 200) GUICtrlCreateLabel("Choose A Switch To Launch", 50, 10) $okbutton = GuiCtrlCreateRadio("swt1", 30, 40, 90, 20) $tkbutton = GuiCtrlCreateRadio("swt2", 30, 60, 60) $ttbutton = GuiCtrlCreateRadio("swt3", 30, 80, 60) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $okbutton ShellExecute ( "terminal.exe","swt1", "%PROGRAMFILES%\HostExplorer\","", ) Case $msg = $tkbutton ShellExecute ( "terminal.exe","swt2", "%PROGRAMFILES%\HostExplorer\","", ) Case $msg = $ttbutton ShellExecute ( "terminal.exe","swt3", "%PROGRAMFILES%\HostExplorer\","", ) Case $msg = $GUI_EVENT_CLOSE MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...") ExitLoop EndSelect WEnd $var = IniReadSection("IP.ini", "SECTION1") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $swt1 = 2 To $var[0][0] MsgBox(4096, "", "$swt1" & $var[$i][0] & @CRLF & "swt1=" & $var[$i][1]) Next EndIf $var = IniReadSection("IP.ini", "SECTION2") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $swt2 = 10 To $var[0][0] MsgBox(4096, "", "swt2" & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf $var = IniReadSection("IP.ini", "SECTION3") If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $zzz = 20 To $var[0][0] MsgBox(4096, "", "swt3" & $var[$i][0] & @CRLF & "Value: " & $var[$i][1]) Next EndIf and here is my ini file: [SECTION1] swt1=263.425.151.99 [SECTION2] swt2=165.236.236.325 [SECTION3] swt3=165.236.653.32 I can get the GUI to pull up the host terminal session but will not read the ip and add to the shell execute. Any help would be greatly appreciated..
PsaltyDS Posted May 25, 2007 Posted May 25, 2007 (edited) OK, here's a completely different way to do it: 1. Changed the INI file format because I didn't understand yours: [Switches] swt1=263.425.151.99 swt2=165.236.236.325 swt3=165.236.653.32 2. Put the GUI in event mode to avoid having to know ahead of time how many switches there might be. You can add or delete switches from the ini file to see that everything automatically adjusts. 3. Made the computer do the work to figure out the GUI dimensions and create the right number of buttons. 4. Put the IP address vice the name "swt1" in the command line for the shell execution. 5. Commented out the ShellExecute() so the demo can be run without HummingBird installed. It pops a debug pop up instead, just uncomment and remove the MsgBox() to go live. Here's my version: expandcollapse popup#include <GUIConstants.au3> ; Get data from ini file $IniFile = @ScriptDir & "\IP.ini" $avSwitches = IniReadSection($IniFile, "Switches") If @error Or $avSwitches[0][0] = 0 Then MsgBox(16, "Error", "Error reading ini file, or no data.") Exit EndIf ; Create GUI Opt("GuiOnEventMode", 1) $hGui = GUICreate("Switch Board", 200, 80 + (30 * $avSwitches[0][0])) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") GUICtrlCreateLabel("Choose A Switch To Launch", 10, 10, 180, 20, $SS_Center) For $n = 1 To $avSwitches[0][0] $avSwitches[$n][0] = GUICtrlCreateRadio($avSwitches[$n][0] & ": " & $avSwitches[$n][1], 30, 10 + ($n * 30), 150, 20) Next $okbutton = GUICtrlCreateButton("OK", 75, 40 + ($avSwitches[0][0] * 30), 50, 30) GUICtrlSetOnEvent(-1, "_OK") GUISetState(@SW_SHOW) While 1 Sleep(20) WEnd Func _OK() For $n = 1 To $avSwitches[0][0] If ControlCommand($hGui, "", $avSwitches[$n][0], "IsChecked") Then ; ShellExecute("terminal.exe", $avSwitches[$n][1], "%PROGRAMFILES%\HostExplorer\", "",) MsgBox(64, "Results", 'Running: ShellExecute("terminal.exe", ' & $avSwitches[$n][1] & ', "%PROGRAMFILES%\HostExplorer\", "",)') EndIf Next EndFunc ;==>_OK Func _Quit() Exit EndFunc ;==>_Quit Cheers! Edited May 25, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
gseller Posted May 26, 2007 Author Posted May 26, 2007 PsaltyDS... That is Awesome!! I believe that will get me going. Thanks So Much!
PsaltyDS Posted May 26, 2007 Posted May 26, 2007 PsaltyDS... That is Awesome!! I believe that will get me going. Thanks So Much!You're welcome.Cheers! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
gseller Posted May 26, 2007 Author Posted May 26, 2007 This is even better than my original code setup, it reads any additional switches added and adds to GUI. How can I devide the switches up into groups? That is why I had my original IP.ini setup with multiple sections. Can this be done using the GUICtrlCreateTabItem with multiple sections in the ini?
PsaltyDS Posted May 26, 2007 Posted May 26, 2007 This is even better than my original code setup, it reads any additional switches added and adds to GUI. How can I devide the switches up into groups? That is why I had my original IP.ini setup with multiple sections. Can this be done using the GUICtrlCreateTabItem with multiple sections in the ini?Sure. Use IniReadSectionNames() to get a list of all the sections, and create a tab for each one.Then read each section and add the switches to the tabs.Doesn't sound hard. Let us know how it comes out. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
gseller Posted June 1, 2007 Author Posted June 1, 2007 (edited) Okie Doke... I have made some great progress but still need some help. Can someone checkout my code and maybe offer some advice? (Not gonna lie LOL A fix would be way cool) Code Edited 05-31-2007 I have my updated code here using IniReadSectionNames to read and setup ini sections for tabs and I have the IniReadSection which is almost working as per below. Can someone see what I am doing wrong that will keep the buttons from pulling up and working? I do wish I could figure out how to change the IniReadSection section name to the current tab clicked on. Working Sample switchboard.au3 expandcollapse popup#include <GUIConstants.au3> $iniFile = @ScriptDir & "\IP.ini";Reads ini file in general $iniSections = IniReadSectionNames($iniFile);Reads ini section names for tabs ; Get data from ini file $iniFile = @ScriptDir & "\IP.ini" $avSwitches = IniReadSection($IniFile, "section 1") If @error Or $avSwitches[0][0] = 0 Then MsgBox(16, "Error", "Error reading ini file, or no data.") Exit EndIf $seH = "5";horizontal positioning of each section in ini file $seL = "5";vertical positioning of each section in ini file ;Creating the GUI ;Opt("GuiOnEventMode", 1) $hGui = GUICreate("GUI Name", 633, 447, 193, 115) $Group1 = GUICtrlCreateGroup("Your Group Box", 16, 16, 601, 417, -1, $WS_EX_TRANSPARENT) $Tab1 = GUICtrlCreateTab(25, 48, 583, 377) GUICtrlSetState(-1,$GUI_SHOW) GUICtrlCreateTabItem("") GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.");Shows error if there is no ini file Else For $i = 1 To $iniSections[0];Setting up the dynamic tabs if $iniSections[$i] <> "Setup" then $tabName = $iniSections[$i] GUICtrlCreateTab($tabName, $seH + 15, $seL * 110,$WS_MAXIMIZE,$WS_EX_TRANSPARENT ) $tab0=GUICtrlCreateTabitem ($tabName) For $n = 1 To $avSwitches[0][0] $avSwitches[$n][0] = GUICtrlCreateRadio($avSwitches[$n][0] & ": " & $avSwitches, 30, 90 + ($n * 30), 400, 20) Next $okbutton = GUICtrlCreateButton("OK", 75, 120 + ($avSwitches[0][0] * 30), 50, 30) GUICtrlSetOnEvent(-1, "_OK") EndIf Next EndIf GUISetState(@SW_SHOW) While 1 $hGui = GUIGetMsg() Switch $hGui Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _OK() For $n = 1 To $avSwitches[0][0] If ControlCommand($hGui, "", $avSwitches[$n][0], "IsChecked") Then ;ShellExecute("HOSTEX32.EXE", $avSwitches[$n][1], "", "",) MsgBox(64, "Results", 'Running: ShellExecute("terminal.exe", ' & $avSwitches[$n][1] & ', "%PROGRAMFILES%\HostExplorer\", "",)') EndIf Next EndFunc ;==>_OK Func _Quit() Exit EndFunc ;==>_Quit Here is my ini example... expandcollapse popup[Setup] [section 1] swt1=263.425.151.99 swt2=165.236.236.325 swt3=165.236.653.32 swt3=265.136.253.95 [section 2] swt1=263.425.151.99 swt2=165.236.236.325 swt3=165.236.653.32 swt3=265.136.253.95 [section 3] swt1=263.425.151.99 swt2=165.236.236.325 swt3=165.236.653.32 swt3=265.136.253.95 [section 4] swt1=263.425.151.99 swt2=165.236.236.325 swt3=165.236.653.32 swt3=265.136.253.95 [section 5] swt1=263.425.151.99 swt2=165.236.236.325 swt3=165.236.653.32 swt3=265.136.253.95 [section 6] swt1=263.425.151.99 swt2=165.236.236.325 swt3=165.236.653.32 swt3=265.136.253.95 Edited June 1, 2007 by gesller
PsaltyDS Posted June 1, 2007 Posted June 1, 2007 I got interested in controls on tabs for my own scripts and did this as an exercise. It doesn't have your functionality in it, but demos the creation of the tabs and checkboxes from an .ini file. It is internally limited to max 8 tabs with max 8 checkboxes each: expandcollapse popup#include <GUIConstants.au3> #include <GuiTab.au3> ; $iniFile = @ScriptDir & "\IP.ini";Reads ini file in general $iniFile = StringTrimRight(@ScriptFullPath, 4) & ".ini" ; Get sections from ini file $iniSections = IniReadSectionNames($iniFile) ; Reads ini section names for tabs If @error Or $iniSections[0] = 0 Then MsgBox(16, "Error", "Error reading .ini file: " & $iniFile) Exit EndIf If $iniSections[0] > 8 Then $iniSections[0] = 8 ; Ignore more than eight sections ; 2D Array of TabItem controls ; [$n][0] = CtrlID of TabItem ; [$n][1] = CtrlID of first checkbox on this tabitem ; ... ; [$n][8] = CtrlID of eighth (max) checkbox on this tabitem Global $avTabs[$iniSections[0]][9] ; Array of button CtrlIDs for the tabitems Global $avTabButtons[$iniSections[0]] ;Creating the GUI Opt("GuiOnEventMode", 1) $hGui = GUICreate("GUI Name", 600, 400) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") ; Setting up the dynamic tabs $TabCtrl = GUICtrlCreateTab(10, 10, 580, 340) For $i = 1 To $iniSections[0] $iniSecData = IniReadSection($iniFile, $iniSections[$i]) If @error Or $iniSecData[0][0] = 0 Then ContinueLoop If $iniSecData[0][0] > 8 Then $iniSecData[0][0] = 8 ; ignore more than 8 items ; TabItems are 0-base numbered $avTabs[$i - 1][0] = GUICtrlCreateTabItem($iniSections[$i]) _GUICtrlTabSetCurSel($TabCtrl, $i - 1) ; Add check boxes For $n = 1 To $iniSecData[0][0] $avTabs[$i - 1][$n] = GUICtrlCreateCheckbox($iniSecData[$n][0] & " = " & $iniSecData[$n][1], 30, 20 + (30 * $n), 540, 20) Next $avTabButtons[$i - 1] = GUICtrlCreateButton("Run These", 250, 300, 100, 30) GUICtrlSetOnEvent(-1, "_TabButton") Next GUICtrlCreateTabItem("") ; Closes out the tabitems ; Add last buttons $OK_Button = GUICtrlCreateButton("OK", 160, 360, 60, 30) GUICtrlSetOnEvent(-1, "_OK_Button") GUICtrlCreateButton("Quit", 380, 360, 60, 30) GUICtrlSetOnEvent(-1, "_Quit") ; GUI Loop GUISetState() While 1 Sleep(20) WEnd Func _TabButton() Local $n, $GuiCtrlID = @GUI_CtrlId For $n = 0 To UBound($avTabButtons) - 1 If $GuiCtrlID = $avTabButtons[$n] Then MsgBox(64, "Tab Button", "You clicked the button on Tab #" & $n) Return EndIf Next EndFunc ;==>_TabButton Func _OK_Button() MsgBox(64, "OK Button", "You clicked the OK button.") EndFunc ;==>_OK_Button Func _Quit() Exit EndFunc ;==>_Quit INI files don't nest sections, so I didn't use the odd [setup] section format you had. Worked with this one instead: [section 1] swt1=10.10.10.10 swt2=11.11.11.11 swt3=12.12.12.12 swt3=13.13.13.13 [section 2] swt1=20.20.20.20 swt2=21.21.21.21 swt3=22.22.22.22 swt3=23.23.23.23 [section 3] swt1=30.30.30.30 swt2=31.31.31.31 swt3=32.32.32.32 swt3=33.33.33.33 [section 4] swt1=40.40.40.40 swt2=41.41.41.41 swt3=42.42.42.42 swt3=43.43.43.43 This exercise helped me with my scripts, hope it helps you with yours. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
gseller Posted June 2, 2007 Author Posted June 2, 2007 Again, You rocked my code.. LOL Thanks Again! Now I will have to see if I can get the radio buttons to lineup in tables across the window in each tab. Tabs are cool, a very nice looking way to show multiple pages of options... Thanks for taking the time to help a fellow wannabe coder(on my part)
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