visler Posted November 12, 2013 Share Posted November 12, 2013 If i would like to connect an array and a gui, how can this be done. So if i have like at colum with alike fields and want to process these (as many as active) and change the value, colour etc, how can i set this up - guess i am sort of lookfor at way to pass the variable to the function proper, but am i not sure. Short example to sort my idea/request: for $i = 1 to $maxidx Increase_by_1(<dont know what to put here>($i)) next Func increase_by_1(<dont know what to put here>) GUICTRLSetData(<<dont know what to put here>, number(GUICTRLRead(<<dont know what to put here>)) + 1)) Gui.... GUI... endfunc Link to comment Share on other sites More sharing options...
water Posted November 12, 2013 Share Posted November 12, 2013 Store the ControlIds when creating the GUI in the same table. Then you can easily loop through the table and change content, color etc. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
kylomas Posted November 12, 2013 Share Posted November 12, 2013 visler, You are going to have to come up with more detail for any better suggestions than water's above. If you are trying to display data in row/col format than a listview is probably what you want. If you want to display rows of data than you may want a listbox. For other controls you can do as water suggested and store the control id's in an array. Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Solution kylomas Posted November 13, 2013 Solution Share Posted November 13, 2013 expandcollapse popup#include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <date.au3> #include <array.au3> #include <GuiListView.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> local $array_with_data[20][7] ; data array to demo filling various controls local $array_for_controls[20][2] ; array of control ids / column 0 = buttons / column 1 = listview items ; fill data array for $1 = 0 to ubound($array_with_data) - 1 for $2 = 0 to ubound($array_with_data,2) - 1 $array_with_data[$1][$2] = stringformat('%02i-%02i', $1+1, $2+1) Next Next ; create listview header local $hdr for $1 = 0 to ubound($array_with_data,2) - 1 $hdr &= 'Col ' & stringformat('%02i',$1+1) & '|' Next $hdr = StringTrimRight($hdr,1) ; create gui local $gui010 = guicreate('Examples of Array Usage with Controls and Data',900,700,-1,-1) guictrlcreatelabel('A LISTVIEW Control is Similar to a Spread Sheet',10,10,370,25, _ bitor($SS_CENTER, $SS_CENTERIMAGE)) guictrlsetfont(-1,10,800) guictrlsetcolor(-1,0xaa0000) local $lv010 = guictrlcreatelistview($hdr,10,35,370,300,-1,bitor($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES)) local $LVsize = controlgetpos($gui010,'',$lv010) guictrlsetfont($lv010,8,800,-1,'courier new') guictrlcreatelabel('ListBox Control',20,400,110,20,bitor($SS_CENTER, $SS_CENTERIMAGE)) guictrlsetfont(-1,10,800) guictrlsetcolor(-1,0xaa0000) local $lb010 = guictrlcreatelist('',35,450,60,220) guictrlcreatelabel('*-Col 2',45,425,200,20) guictrlsetfont(-1,7,800,-1,'courier new') guictrlcreatelabel('Combo Control',140,400,110,20,bitor($SS_CENTER, $SS_CENTERIMAGE)) guictrlsetfont(-1,10,800,-1) guictrlsetcolor(-1,0xaa0000) local $cb010 = GUICtrlCreateCombo('',155,450,80,20) _GUICtrlComboBox_SetCueBanner($cb010, "Selections...") guictrlcreatelabel('*-Col 5',175,425,200,20) guictrlsetfont(-1,7,800,-1,'courier new') local $grp010 = guictrlcreategroup('',450,65,50,500) local $lbl010 = guictrlcreatelabel('Press a Button to See the Corresponding Listview Row',400,15,150,50,$SS_CENTER) guictrlsetfont(-1,9,800,-1,'Comic Sans MS') guictrlcreatelabel('"Click on any entry in the Listview, List or Combo controls to see the controls value in the edit box"', _ 125,520,200,200) guictrlsetfont(-1,10,800,-1,'Comic Sans MS') ; create 1 button for each row of the array and put the buttons in the group control for $1 = 0 to ubound($array_with_data) - 1 $array_for_controls[$1][0] = GUICtrlCreateButton($1+1,460,85+$1*23,30,20) GUICtrlSetBkColor(-1, '0x' & hex(random(0,255,1),2) & hex(random(0,255,1),2) & hex(random(0,255,1),2)) ; just dick'in around setting random colors guictrlsetfont(-1,10,800) next GUICtrlCreateGroup('',99,99,1,1) local $edt010 = guictrlcreateedit('',550,70,320,600,bitor($ES_READONLY, $WS_HSCROLL, $WS_VSCROLL)) guictrlsetfont(-1,7,800,-1,'Lucida Console') guictrlsetdata($edt010,'Application Started at ' & _now() & @crlf,1) ; populate the listview with array data local $lv_item for $1 = 0 to ubound($array_with_data) - 1 for $2 = 0 to ubound($array_with_data,2) - 1 $lv_item &= $array_with_data[$1][$2] & '|' next $array_for_controls[$1][1] = GUICtrlCreateListViewItem($lv_item,$lv010) $lv_item = '' next ; adjust the listview to distribute the columns evenly across the control for $1 = 0 to _GUICtrlListView_GetColumnCount($lv010) _GUICtrlListView_SetColumnWidth($lv010, $1, ($LVSize[2])/_GUICtrlListView_GetColumnCount($lv010)-3) next ; populate the listbox with column 2 of the data array local $lb_str for $1 = 0 to ubound($array_with_data) - 1 $lb_str &= $array_with_data[$1][1] & '|' Next $lb_str = stringtrimright($lb_str,1) guictrlsetdata($lb010,$lb_str) ; populate the combo control with column 5 of the data array $lb_str = '' for $1 = 0 to ubound($array_with_data) - 1 $lb_str &= $array_with_data[$1][4] & '|' Next $lb_str = stringtrimright($lb_str,1) guictrlsetdata($cb010,$lb_str) guisetstate() local $msg while 1 $msg = guigetmsg() switch $msg case $GUI_EVENT_CLOSE Exit ; test for a listview item control case $array_for_controls[0][1] to $array_for_controls[ubound($array_for_controls) - 1][1] guictrlsetdata($edt010,@crlf & 'ListView Row from mouse select ------' & @crlf & guictrlread(guictrlread($lv010)) & @crlf,1) case $lb010 guictrlsetdata($edt010,@crlf & 'Entry From List ------' & @crlf & guictrlread($lb010) & @crlf,1) case $cb010 guictrlsetdata($edt010,@crlf & 'Entry From combo ------' & @crlf & guictrlread($cb010) & @crlf,1) ; test for a button control case $array_for_controls[0][0] to $array_for_controls[ubound($array_for_controls) - 1][0] for $1 = 0 to ubound($array_for_controls) - 1 if $msg = $array_for_controls[$1][0] then guictrlsetdata($edt010,@crlf & 'ListView Row from button push ------' & @crlf & _guictrllistview_getitemtextstring($lv010,$1) & @crlf,1) exitloop EndIf next EndSwitch WEnd Some examples... visler 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
visler Posted November 13, 2013 Author Share Posted November 13, 2013 expandcollapse popup#include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <date.au3> #include <array.au3> #include <GuiListView.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> local $array_with_data[20][7] ; data array to demo filling various controls local $array_for_controls[20][2] ; array of control ids / column 0 = buttons / column 1 = listview items ; fill data array for $1 = 0 to ubound($array_with_data) - 1 for $2 = 0 to ubound($array_with_data,2) - 1 $array_with_data[$1][$2] = stringformat('%02i-%02i', $1+1, $2+1) Next Next ; create listview header local $hdr for $1 = 0 to ubound($array_with_data,2) - 1 $hdr &= 'Col ' & stringformat('%02i',$1+1) & '|' Next $hdr = StringTrimRight($hdr,1) ; create gui local $gui010 = guicreate('Examples of Array Usage with Controls and Data',900,700,-1,-1) guictrlcreatelabel('A LISTVIEW Control is Similar to a Spread Sheet',10,10,370,25, _ bitor($SS_CENTER, $SS_CENTERIMAGE)) guictrlsetfont(-1,10,800) guictrlsetcolor(-1,0xaa0000) local $lv010 = guictrlcreatelistview($hdr,10,35,370,300,-1,bitor($LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES)) local $LVsize = controlgetpos($gui010,'',$lv010) guictrlsetfont($lv010,8,800,-1,'courier new') guictrlcreatelabel('ListBox Control',20,400,110,20,bitor($SS_CENTER, $SS_CENTERIMAGE)) guictrlsetfont(-1,10,800) guictrlsetcolor(-1,0xaa0000) local $lb010 = guictrlcreatelist('',35,450,60,220) guictrlcreatelabel('*-Col 2',45,425,200,20) guictrlsetfont(-1,7,800,-1,'courier new') guictrlcreatelabel('Combo Control',140,400,110,20,bitor($SS_CENTER, $SS_CENTERIMAGE)) guictrlsetfont(-1,10,800,-1) guictrlsetcolor(-1,0xaa0000) local $cb010 = GUICtrlCreateCombo('',155,450,80,20) _GUICtrlComboBox_SetCueBanner($cb010, "Selections...") guictrlcreatelabel('*-Col 5',175,425,200,20) guictrlsetfont(-1,7,800,-1,'courier new') local $grp010 = guictrlcreategroup('',450,65,50,500) local $lbl010 = guictrlcreatelabel('Press a Button to See the Corresponding Listview Row',400,15,150,50,$SS_CENTER) guictrlsetfont(-1,9,800,-1,'Comic Sans MS') guictrlcreatelabel('"Click on any entry in the Listview, List or Combo controls to see the controls value in the edit box"', _ 125,520,200,200) guictrlsetfont(-1,10,800,-1,'Comic Sans MS') ; create 1 button for each row of the array and put the buttons in the group control for $1 = 0 to ubound($array_with_data) - 1 $array_for_controls[$1][0] = GUICtrlCreateButton($1+1,460,85+$1*23,30,20) GUICtrlSetBkColor(-1, '0x' & hex(random(0,255,1),2) & hex(random(0,255,1),2) & hex(random(0,255,1),2)) ; just dick'in around setting random colors guictrlsetfont(-1,10,800) next GUICtrlCreateGroup('',99,99,1,1) local $edt010 = guictrlcreateedit('',550,70,320,600,bitor($ES_READONLY, $WS_HSCROLL, $WS_VSCROLL)) guictrlsetfont(-1,7,800,-1,'Lucida Console') guictrlsetdata($edt010,'Application Started at ' & _now() & @crlf,1) ; populate the listview with array data local $lv_item for $1 = 0 to ubound($array_with_data) - 1 for $2 = 0 to ubound($array_with_data,2) - 1 $lv_item &= $array_with_data[$1][$2] & '|' next $array_for_controls[$1][1] = GUICtrlCreateListViewItem($lv_item,$lv010) $lv_item = '' next ; adjust the listview to distribute the columns evenly across the control for $1 = 0 to _GUICtrlListView_GetColumnCount($lv010) _GUICtrlListView_SetColumnWidth($lv010, $1, ($LVSize[2])/_GUICtrlListView_GetColumnCount($lv010)-3) next ; populate the listbox with column 2 of the data array local $lb_str for $1 = 0 to ubound($array_with_data) - 1 $lb_str &= $array_with_data[$1][1] & '|' Next $lb_str = stringtrimright($lb_str,1) guictrlsetdata($lb010,$lb_str) ; populate the combo control with column 5 of the data array $lb_str = '' for $1 = 0 to ubound($array_with_data) - 1 $lb_str &= $array_with_data[$1][4] & '|' Next $lb_str = stringtrimright($lb_str,1) guictrlsetdata($cb010,$lb_str) guisetstate() local $msg while 1 $msg = guigetmsg() switch $msg case $GUI_EVENT_CLOSE Exit ; test for a listview item control case $array_for_controls[0][1] to $array_for_controls[ubound($array_for_controls) - 1][1] guictrlsetdata($edt010,@crlf & 'ListView Row from mouse select ------' & @crlf & guictrlread(guictrlread($lv010)) & @crlf,1) case $lb010 guictrlsetdata($edt010,@crlf & 'Entry From List ------' & @crlf & guictrlread($lb010) & @crlf,1) case $cb010 guictrlsetdata($edt010,@crlf & 'Entry From combo ------' & @crlf & guictrlread($cb010) & @crlf,1) ; test for a button control case $array_for_controls[0][0] to $array_for_controls[ubound($array_for_controls) - 1][0] for $1 = 0 to ubound($array_for_controls) - 1 if $msg = $array_for_controls[$1][0] then guictrlsetdata($edt010,@crlf & 'ListView Row from button push ------' & @crlf & _guictrllistview_getitemtextstring($lv010,$1) & @crlf,1) exitloop EndIf next EndSwitch WEnd Some examples... Thx, i think this might be a way for solving my problems/requests Link to comment Share on other sites More sharing options...
visler Posted November 13, 2013 Author Share Posted November 13, 2013 visler, You are going to have to come up with more detail for any better suggestions than water's above. If you are trying to display data in row/col format than a listview is probably what you want. If you want to display rows of data than you may want a listbox. For other controls you can do as water suggested and store the control id's in an array. Good Luck, kylomas I think i can use the solution from below. I basicly just wanted a way of being able to process a guiobject within in function, so alike operation can be done within function and not end like a longer novell of coding to process more object when these object is almost alike. 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