rezz Posted December 23, 2010 Share Posted December 23, 2010 (edited) I'm trying to setup a multiple tab gui to act as a logger and have a problem figuring out how to code my buttons, fields, and check boxes to act independently of each other on the 5 different tabs. Here's an example of how I have it setup: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <GuiConstants.au3> #include <Array.au3> #include<File.au3> #include <EditConstants.au3> #include <IE.au3> #include <String.au3> #include <inet.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Multiple Independent Tabs", 400, 400, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2) $hTab = GUICtrlCreateTab(10, 10, 480, 480) ; Create tabitems For $i = 0 To 4 GUICtrlCreateTabItem("Tab " & $i) ;GUICtrlCreateButton("Built-In " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30) $NotesButton = GUICtrlCreateButton("Notes", 20, 380, 60, 20) $CButton = GUICtrlCreateButton("Test 1", 90, 380, 50, 20) $PButton = GUICtrlCreateButton("Test 2", 150, 380, 60, 20) $SButton = GUICtrlCreateButton("Test 3", 220, 380, 60, 20) $ResetButton = GUICtrlCreateButton("Reset", 320, 330, 50, 20) $ApptID = GUICtrlCreateInput("", 60, 40, 110, 20) $Name = GUICtrlCreateInput("", 60, 65, 110, 20) $BillingPhone = GUICtrlCreateInput("", 60, 90, 110, 20) $ContactPhone = GUICtrlCreateInput("", 60, 115, 110, 20) $Mac = GUICtrlCreateInput("", 60, 140, 110, 20) $Notes = GUICtrlCreateInput("", 20, 270, 290, 100, $ES_MULTILINE + $ES_WANTRETURN + $WS_VSCROLL) $ResetButton = GUICtrlCreateButton("Reset", 320, 330, 50, 20) $Checkbox_9 = GUICtrlCreateCheckbox("Test1", 12, 170, 120, 20) $Checkbox_10 = GUICtrlCreateCheckbox("Test2", 12, 190, 120, 20) $Label_18 = GUICtrlCreateLabel("Appt ID", 12, 40, 50, 30) ;$Label_19 = GUICtrlCreateLabel("Name", 12, 65, 20, 1) $Label_20 = GUICtrlCreateLabel("Name", 12, 65, 40, 20) $Label_21 = GUICtrlCreateLabel("Phone", 12, 90, 80, 20) $Label_22 = GUICtrlCreateLabel("Alt#", 12, 115, 70, 20) $Label_23 = GUICtrlCreateLabel("Mac", 12, 140, 60, 20) $Label_24 = GUICtrlCreateLabel("Notes:", 20, 250, 60, 20) $Label_25 = GUICtrlCreateLabel("Time:" & " " & @HOUR & @MIN & " " & @MON & "-" & @MDAY & "-" & @YEAR, 260, 30, 90, 40) Next GUICtrlCreateTabItem("") ; Create UDF controls ;~ For $i = 0 To 4 ;~ $hButtons[$i] = _GUICtrlButton_Create($hGUI, "UDF " & $i, 20 + ($i * 100), 80 + ($i * 50),80, 30) ;~ Next ; Hide the controls so only the one on the first tab is visible ;~ WinSetState($hButtons[1], "", @SW_HIDE) ;~ WinSetState($hButtons[2], "", @SW_HIDE) GUISetState() ; This is the current active tab $iLastTab = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ResetButton _Clear_All() Case $hTab ; Check which Tab is active $iCurrTab = GUICtrlRead($hTab) ; If the Tab has changed If $iCurrTab <> $iLastTab Then ; Show/Hide controls as required Switch $iCurrTab Case 0 ;WinSetState($hButtons[1], "", @SW_HIDE) ;WinSetState($hButtons[2], "", @SW_HIDE) ;WinSetState($hButtons[0], "", @SW_SHOW) Case 1 ;WinSetState($hButtons[0], "", @SW_HIDE) ;~ WinSetState($hButtons[2], "", @SW_HIDE) ;WinSetState($hButtons[1], "", @SW_SHOW) Case 2 ;~ WinSetState($hButtons[0], "", @SW_HIDE) ;~ WinSetState($hButtons[1], "", @SW_HIDE) ;WinSetState($hButtons[2], "", @SW_SHOW) Case 3 ;WinSetState($hButtons[2], "", @SW_SHOW) Case 4 ;WinSetState($hButtons[2], "", @SW_SHOW) EndSwitch ; Store the value for future comparisons $iLastTab = $iCurrTab EndIf EndSwitch WEnd Func _Clear_All() ;clear all check boxes For $i = 1 To 50 GUICtrlSetState($i, $GUI_UNCHECKED) Next For $i = 42 To 45 GUICtrlSetData($i, "") Next EndFunc ;==>_Clear_All Func _SelfRestart() If @Compiled Then Run(FileGetShortName(@ScriptFullPath)) Else Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc ;==>_SelfRestart Where and how can I setup my button,fields, and checkbox controls so that one tab will not affect the other tabs info when they are clicked or have data entered? Currently the Tab items are independent of each other tab but I can't seem to figure out how to get the buttons to work. I have tried various ways and nothing seems to work. In the above code I have the reset button set to use Func _Clear_All() to clear the checkboxes and would also like it to clear the form fields. The buttons at the bottom will be used to submit the tab data by individual tabs also. Please help me get past this one hurdle. So far everything has gone fairly well but I am stumped here. Edited January 5, 2011 by rezz Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 23, 2010 Moderators Share Posted December 23, 2010 rezz,At the moment you are overwriting the ControlIDs of each each set of controls as you create a new tab - you only store those of the last created tab. Use arrays to hold the ControlIDs for each of the buttons, etc on each tab. Then you can address the control on Tab# as $aArray[#] and so differentiate between them. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rezz Posted December 23, 2010 Author Share Posted December 23, 2010 Thanks for that. I'm having trouble enough with the easy part without getting into arrays. Any help on that would be appreciated. If you can get me started I can probably go from there. This is just an example I put together for posting. The other gui is similar but have more buttons and check boxes. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 23, 2010 Moderators Share Posted December 23, 2010 rezz, If you can get me startedHow did I know you were going to ask that? Here is a version of your script with arrays to hold the ControlIDs for the controls. I have added code for the Reset buttons so that you can see how to use the Tab index to action the correct element within the various arrays - you can see that you only reset the tab on which the Reset button is located: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <GuiConstants.au3> #include <Array.au3> #include<File.au3> #include <EditConstants.au3> #include <IE.au3> #include <String.au3> #include <inet.au3> #include <WindowsConstants.au3> Global $NotesButton[5] Global $CTSMButton[5] Global $PipButton[5] Global $SiebelButton[5] Global $ResetButton[5] Global $ApptID[5] Global $Name[5] Global $BillingPhone[5] Global $ContactPhone[5] Global $Mac[5] Global $Notes[5] Global $Checkbox_9[5] Global $Checkbox_10[5] $hGUI = GUICreate("Multiple Independent Tabs", 400, 400, (@DesktopWidth - 400) / 2, (@DesktopHeight - 400) / 2) $hTab = GUICtrlCreateTab(10, 10, 480, 480) ; Create tabitems For $i = 0 To 4 GUICtrlCreateTabItem("Tab " & $i) ;GUICtrlCreateButton("Built-In " & $i, 20 + ($i * 100), 40 + ($i * 50), 80, 30) $NotesButton[$i] = GUICtrlCreateButton("Notes", 20, 380, 60, 20) $CTSMButton[$i] = GUICtrlCreateButton("Test 1", 90, 380, 50, 20) $PipButton[$i] = GUICtrlCreateButton("Test 2", 150, 380, 60, 20) $SiebelButton[$i] = GUICtrlCreateButton("Test 3", 220, 380, 60, 20) $ResetButton[$i] = GUICtrlCreateButton("Reset", 320, 330, 50, 20) $ApptID[$i] = GUICtrlCreateInput("", 60, 40, 110, 20) $Name[$i] = GUICtrlCreateInput("", 60, 65, 110, 20) $BillingPhone[$i] = GUICtrlCreateInput("", 60, 90, 110, 20) $ContactPhone[$i] = GUICtrlCreateInput("", 60, 115, 110, 20) $Mac[$i] = GUICtrlCreateInput("", 60, 140, 110, 20) $Notes[$i] = GUICtrlCreateInput("", 20, 270, 290, 100, $ES_MULTILINE + $ES_WANTRETURN + $WS_VSCROLL) $Checkbox_9[$i] = GUICtrlCreateCheckbox("Test1", 12, 170, 120, 20) $Checkbox_10[$i] = GUICtrlCreateCheckbox("Test2", 12, 190, 120, 20) GUICtrlCreateLabel("Appt ID", 12, 40, 50, 30) ; GUICtrlCreateLabel("Name", 12, 65, 20, 1) GUICtrlCreateLabel("Name", 12, 65, 40, 20) GUICtrlCreateLabel("Phone", 12, 90, 80, 20) GUICtrlCreateLabel("Alt#", 12, 115, 70, 20) GUICtrlCreateLabel("Mac", 12, 140, 60, 20) GUICtrlCreateLabel("Notes:", 20, 250, 60, 20) GUICtrlCreateLabel("Time:" & " " & @HOUR & @MIN & " " & @MON & "-" & @MDAY & "-" & @YEAR, 260, 30, 90, 40) Next GUICtrlCreateTabItem("") ; Create UDF controls ;~ For $i = 0 To 4 ;~ $hButtons[$i] = _GUICtrlButton_Create($hGUI, "UDF " & $i, 20 + ($i * 100), 80 + ($i * 50),80, 30) ;~ Next ; Hide the controls so only the one on the first tab is visible ;~ WinSetState($hButtons[1], "", @SW_HIDE) ;~ WinSetState($hButtons[2], "", @SW_HIDE) GUISetState() ; This is the current active tab $iLastTab = 0 While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $ResetButton[0] _Clear_All(0) Case $ResetButton[1] _Clear_All(1) Case $ResetButton[2] _Clear_All(2) Case $ResetButton[3] _Clear_All(3) Case $ResetButton[4] _Clear_All(4) Case $hTab ; Check which Tab is active $iCurrTab = GUICtrlRead($hTab) ; If the Tab has changed If $iCurrTab <> $iLastTab Then ; Show/Hide controls as required Switch $iCurrTab Case 0 ;WinSetState($hButtons[1], "", @SW_HIDE) ;WinSetState($hButtons[2], "", @SW_HIDE) ;WinSetState($hButtons[0], "", @SW_SHOW) Case 1 ;WinSetState($hButtons[0], "", @SW_HIDE) ;~ WinSetState($hButtons[2], "", @SW_HIDE) ;WinSetState($hButtons[1], "", @SW_SHOW) Case 2 ;~ WinSetState($hButtons[0], "", @SW_HIDE) ;~ WinSetState($hButtons[1], "", @SW_HIDE) ;WinSetState($hButtons[2], "", @SW_SHOW) Case 3 ;WinSetState($hButtons[2], "", @SW_SHOW) Case 4 ;WinSetState($hButtons[2], "", @SW_SHOW) EndSwitch ; Store the value for future comparisons $iLastTab = $iCurrTab EndIf EndSwitch WEnd Func _Clear_All($iIndex) ;clear all check boxes on the tab GUICtrlSetState($Checkbox_9[$iIndex] , $GUI_UNCHECKED) GUICtrlSetState($Checkbox_10[$iIndex] , $GUI_UNCHECKED) ;clear all inputs on the tab GUICtrlSetData($ApptID[$iIndex], "") GUICtrlSetData($Name[$iIndex], "") GUICtrlSetData($BillingPhone[$iIndex], "") GUICtrlSetData($ContactPhone[$iIndex], "") GUICtrlSetData($Mac[$iIndex], "") GUICtrlSetData($Notes[$iIndex], "") EndFunc ;==>_Clear_All Func _SelfRestart() If @Compiled Then Run(FileGetShortName(@ScriptFullPath)) Else Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc ;==>_SelfRestart Please ask if anything is unclear. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rezz Posted December 23, 2010 Author Share Posted December 23, 2010 Beautiful! Now to dig in and get it working with all the buttons Thank you very much. Link to comment Share on other sites More sharing options...
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