PerryRaptor Posted April 16, 2005 Posted April 16, 2005 I have questions... Question #1: How do I fill GuiCtrlSetData() from a multi-dimensional array? I want to populate GuiCtrlSetData() with the contents of only column[0] for every row, aka "lines", contained in the multi-dimensional array. Question #2: After making a selection with GUICtrlCreateCombo() how do I capture the remaining columns, columns 1 thru 3, contents associated with this specific row? I want to store each column[$var] to a memory varible too.
PerryRaptor Posted April 16, 2005 Author Posted April 16, 2005 (edited) This is a continuation of, "Filling Arrays from CSV Files". I'm not using the COM feature.http://www.autoitscript.com/forum/index.php?showtopic=10131 Edited April 16, 2005 by PerryRaptor
PerryRaptor Posted April 17, 2005 Author Posted April 17, 2005 After much trial and error I've answered Question #1: How do I fill GuiCtrlSetData() from a multi-dimensional array? I want to populate GuiCtrlSetData() with the contents of only column[0] for every row, aka "lines", contained in the multi-dimensional array. I've created the test.csv file as: $Ay[0][0]='TX' $Ay[0][1]='Dallas' $Ay[0][2]='Ft. Worth' $Ay[0][3]=' ' $Ay[1][0]='NM' $Ay[1][1]='Taos' $Ay[1][2]='Albuquerque' $Ay[1][3]='Belen' $Ay[2][0]='FL' $Ay[2][1]='Miami' $Ay[2][2]='Coco Beach' $Ay[2][3]='Tampa' $Ay[3][0]='AZ' Here is the script thus far: expandcollapse popup#include <GUIConstants.au3> #include <File.au3> $in_filename = "test.csv" Dim $lines,$Display, $NumCols _FileReadToArray($in_filename, $lines) $Columns = StringSplit($lines[1], ",") $NumCols=$Columns[0] MsgBox(0,"how many columns", $NumCols) Dim $array[ $lines[0] ][ $Columns[0] ] For $i = 1 To $lines[0] $Columns = StringSplit($lines[$i], ",") If $Columns[0] = 1 Then Continueloop For $j = 1 To $Columns[0] $array[$i-1][$j-1] = $Columns[$j] Next Next $Rows=$Lines[0]-1 MsgBox(0,"How many Rows", $Rows) For $i = 1 To $lines[0]-1 ;---------------------------------------------------------------------- ;Display Entire CSV File converted to an Array ;---------------------------------------------------------------------- For $j = 1 To $NumCols $Display = $Display&"array["&String($i-1)&"]["&String($j-1)&"]="&chr(9)&$array[$i-1][$j-1]&@CRLF Next Next MsgBox(4096, "Here is your CSV File",$Display) ;---------------------------------------------------------------------- ;Display only the contents of Row 1, Column A ;---------------------------------------------------------------------- MsgBox(0,"Array[Row1][ColumnA]", $Array[0][0]) ;---------------------------------------------------------------------- ;Display the contents of Column A and all rows ;---------------------------------------------------------------------- Dim $ColumnA, $AllColumnA $M = 0 While $m <= $Rows -1 $ColumnA=$Array[$m][0] & "|" $m = $m + 1 $AllColumnA=$AllColumnA & $ColumnA Wend MsgBox(0,"AllColumnA", $AllColumnA) ;---------------------------------------------------------------------- ;Display the contents of Column A in a ComboBox ;---------------------------------------------------------------------- GUICreate("ComboBox view for contents of Column A for all Rows",400,100,-1,-1) GUICtrlCreateCombo ("", 10,10,100) GUICtrlSetData(-1,$AllColumnA) GUISetState () While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend All I need now is some help with Question #2: After making a selection with GUICtrlCreateCombo() how do I capture the remaining columns, columns 1 thru 3, contents associated with this specific row? I want to store each column[$var] to a memory varible too.
SvenP Posted April 17, 2005 Posted April 17, 2005 [snap]All I need now is some help with Question #2: After making a selection with GUICtrlCreateCombo() how do I capture the remaining columns, columns 1 thru 3, contents associated with this specific row? I want to store each column[$var] to a memory varible too.<{POST_SNAPBACK}>Hello PerryRaptor,I'm not an expert on the GUI stuff, but when I remember it well, there is no way to return the chosen index number from a Combobox. You can only retrieve the chosen data with GUICtrlRead. So in order to know the corresponding index in your array, you will have to make a 'search function' that searches for the chosen value through your array and returns the index.Maybe someone should add functionality to GUICtrlGetState() to retrieve the chosen index from a combobox (it does currently for a chosen column in a listview). That should make life much easier.Regards,-Sven
PerryRaptor Posted April 17, 2005 Author Posted April 17, 2005 Thanks for the look Sven. I'm going to try the _ArrayBinarySearch() to see if it can search the first dimension in the array for what GUICtrlRead() returns. I'm guessing that _ArrayBinarySearch() can return the index number. Also, I'm guessing that it can work the first dimension since the helpfile says it's only for 1 dimensional arrays. The CSV File is important to my project. I do not want to loose it for a work around. The data in the CSV File is easily edited for additions, updates, and deletions.
GaryFrost Posted April 17, 2005 Posted April 17, 2005 (edited) add the following to your while If $msg = $h_cmb Then MsgBox(0,"",_GUICtrlComboBoxIndex($h_cmb)) EndIf add this function Func _GUICtrlComboBoxIndex($h_combobox) Dim $CB_GETCURSEL = 0x147 Return GUICtrlSendMsg ( $h_combobox, $CB_GETCURSEL , 0, 0 ) EndFunc Edit: forgot you need to assign the control id $h_cmb = GUICtrlCreateCombo ("", 10,10,100) Edited April 17, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
PerryRaptor Posted April 17, 2005 Author Posted April 17, 2005 Didn't work GaFrost. probably because I've made changes since the posted code. Here is my current evolution with your additions. Also, I'm using AutoIT version 3.1.1 and not the current beta. expandcollapse popup#include <GUIConstants.au3> #include <File.au3> $in_filename = "test.csv" Dim $lines,$Display, $NumCols _FileReadToArray($in_filename, $lines) $Columns = StringSplit($lines[1], ",") $NumCols=$Columns[0] MsgBox(0,"how many columns", $NumCols) Dim $array[ $lines[0] ][ $Columns[0] ] For $i = 1 To $lines[0] $Columns = StringSplit($lines[$i], ",") If $Columns[0] = 1 Then Continueloop For $j = 1 To $Columns[0] $array[$i-1][$j-1] = $Columns[$j] Next Next $Rows=$Lines[0]-1 MsgBox(0,"How many Rows", $Rows) For $i = 1 To $lines[0]-1 ;---------------------------------------------------------------------- ;Display Entire CSV File converted to an Array ;---------------------------------------------------------------------- For $j = 1 To $NumCols $Display = $Display&"array["&String($i-1)&"]["&String($j-1)&"]="&chr(9)&$array[$i-1][$j-1]&@CRLF Next Next MsgBox(4096, "Here is your CSV File",$Display) ;---------------------------------------------------------------------- ;Display only the contents of Row 1, Column A ;---------------------------------------------------------------------- MsgBox(0,"Array[Row1][ColumnA]", $Array[0][0]) ;---------------------------------------------------------------------- ;Display the contents of Column A and all rows ;---------------------------------------------------------------------- Dim $ColumnA, $AllColumnA $M = 0 While $m <= $Rows -1 $ColumnA=$Array[$m][0] & "|" $m = $m + 1 $AllColumnA=$AllColumnA & $ColumnA Wend MsgBox(0,"AllColumnA", $AllColumnA) ;---------------------------------------------------------------------- ;Display the contents of Column A in a ComboBox ;---------------------------------------------------------------------- GUICreate("ComboBox view for contents of Column A for all Rows",400,100,-1,-1) GUICtrlCreateCombo ("", 10,10,100) GUICtrlSetData(-1,$AllColumnA) $h_cmb = GUICtrlCreateCombo ("", 140,10,100) GUISetState () While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $h_cmb Then MsgBox(0,"",_GUICtrlComboBoxIndex($h_cmb)) EndIf Wend Func _GUICtrlComboBoxIndex($h_combobox) Dim $CB_GETCURSEL = 0x147 Return GUICtrlSendMsg ( $h_combobox, $CB_GETCURSEL , 0, 0 ) EndFunc
GaryFrost Posted April 17, 2005 Posted April 17, 2005 (edited) change GUICtrlCreateCombo ("", 10,10,100) GUICtrlSetData(-1,$AllColumnA) $h_cmb = GUICtrlCreateCombo ("", 140,10,100) to $h_cmb = GUICtrlCreateCombo ("", 10,10,100) GUICtrlSetData(-1,$AllColumnA) Edited April 17, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
GaryFrost Posted April 17, 2005 Posted April 17, 2005 For those interested in some combo box functions expandcollapse popupFunc _GUICtrlComboBoxSelectedIndex($h_combobox) ; An application sends a CB_GETCURSEL message to retrieve the ; index of the currently selected item, if any, in the list box of a combo box. Dim $CB_GETCURSEL = 0x147 Return GUICtrlSendMsg ( $h_combobox, $CB_GETCURSEL , 0, 0 ) EndFunc Func _GUICtrlComboBoxCount($h_combobox) ; An application sends a CB_GETCOUNT message to retrieve the ; number of items in the list box of a combo box. Dim $CB_GETCOUNT = 0x146 Return GUICtrlSendMsg ( $h_combobox, $CB_GETCOUNT , 0, 0 ) EndFunc Func _GUICtrlComboBoxFind($h_combobox,$s_search,$i_exact=0) ; An application sends a CB_FINDSTRING message to search the ; list box of a combo box for an item beginning with the characters ; in a specified string. Dim $CB_FINDSTRING = 0x14C ; An application sends a CB_FINDSTRINGEXACT message to find the first ; list box string in a combo box that matches the string specified in ; the $s_search parameter. Dim $CB_FINDSTRINGEXACT = 0x158 If($i_exact) Then Return GUICtrlSendMsg ( $h_combobox, $CB_FINDSTRINGEXACT , -1, $s_search ) Else Return GUICtrlSendMsg ( $h_combobox, $CB_FINDSTRING , -1, $s_search ) EndIf EndFunc Func _GUICtrlComboBoxAddItem($h_combobox, $s_text,$i_location = -1) ; An application sends a CB_INSERTSTRING message to insert a string into ; the list box of a combo box. Unlike the CB_ADDSTRING message, the ; CB_INSERTSTRING message does not cause a list with the CBS_SORT style ; to be sorted. ; if $i_location is omitted then we append to end of list Dim $CB_INSERTSTRING = 0x14A Return GUICtrlSendMsg ( $h_combobox, $CB_INSERTSTRING , $i_location, $s_text ) EndFunc Func _GUICtrlComboBoxClearItems($h_combobox) ; An application sends a CB_RESETCONTENT message to remove all items from ; the list box and edit control of a combo box. Dim $CB_RESETCONTENT = 0x14B Return GUICtrlSendMsg ( $h_combobox, $CB_RESETCONTENT , 0, 0 ) EndFunc Func _GUICtrlCombBoxSelectString($h_combobox,$s_search,$i_StartAt = -1) ; An application sends a CB_SELECTSTRING message to search the list of ; a combo box for an item that begins with the characters in a specified string. ; If a matching item is found, it is selected and copied to the edit control. ; if $i_StartAt is omitted then search entire list ; otherwise it Specifies the zero-based index of the item preceding ; the first item to be searched. When the search reaches the bottom ; of the list, it continues from the top of the list back to the item ; specified by the $i_StartAt parameter Dim $CB_SELECTSTRING = 0x14D Return GUICtrlSendMsg ( $h_combobox, $CB_SELECTSTRING , $i_StartAt, $s_search ) EndFunc Func _GUICtrlComboBoxSetSel($h_combobox,$i_index) ; An application sends a CB_SETCURSEL message to select a string in the list ; of a combo box. If necessary, the list scrolls the string into view. The text ; in the edit control of the combo box changes to reflect the new selection, and ; any previous selection in the list is removed. Dim $CB_SETCURSEL = 0x14E Return GUICtrlSendMsg ( $h_combobox, $CB_SETCURSEL , $i_index, 0 ) EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
PerryRaptor Posted April 20, 2005 Author Posted April 20, 2005 Thanks everyone that helped me out!!! This works with version 3.1.1. expandcollapse popup#include <GUIConstants.au3> #include <File.au3> $in_filename = "test.csv" Dim $lines,$Display, $NumCols _FileReadToArray($in_filename, $lines) $Columns = StringSplit($lines[1], ",") $NumCols=$Columns[0] Dim $array[ $lines[0] ][ $Columns[0] ] For $i = 1 To $lines[0] $Columns = StringSplit($lines[$i], ",") If $Columns[0] = 1 Then Continueloop For $j = 1 To $Columns[0] $array[$i-1][$j-1] = $Columns[$j] Next Next $Rows=$Lines[0]-1 For $i = 1 To $lines[0]-1 ;--------------------------------------------------------------------- ;Display Entire CSV File converted to an Array ;--------------------------------------------------------------------- For $j = 1 To $NumCols $Display = $Display&"array["&String($i-1)&"]["&String($j-1)&"]="&chr(9)&$array[$i-1][$j-1]&@CRLF Next Next MsgBox(4096, "Here is your CSV File",$Display) ;--------------------------------------------------------------------- ;Get the contents of Column A for every row ; Add a "|" at the end of each item ;--------------------------------------------------------------------- Dim $ColumnA, $AllColumnA, $H_cmb, $H_ComboBox $M = 0 While $m <= $Rows -1 $ColumnA=$Array[$m][0] & "|" $m = $m + 1 $AllColumnA=$AllColumnA & $ColumnA Wend ;--------------------------------------------------------------------- ;Display the contents of Column A in a ComboBox ; Display Column B contents in an InputBox ; Display Column C contents in a GuiCtrlCreateLabel ;--------------------------------------------------------------------- GUICreate("ComboBox view for contents of Column A for all Rows",400,100,-1,-1) $h_cmb = GUICtrlCreateCombo("", 10,10,100) GUICtrlSetData(-1,$AllColumnA) GUISetState () While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $h_cmb Then GuiCtrlCreateInput(_GUICtrlComboBoxIndex($h_cmb), 115,10,80) EndIf Wend ;--------------------------------------------------------------------- ;Function used with "Display the contents of Column A in a ComboBox" ; Returns the row (aka Line Number) for the item selected ; Returns the data contained in Columns B and C ;--------------------------------------------------------------------- Func _GUICtrlComboBoxIndex($H_ComboBox) Dim $CB_GETCURSEL = 0x147 $Row_Return = GUICtrlSendMsg ( $H_ComboBox, $CB_GETCURSEL , 0, 0 ) $H_ComboBox = $Array[$Row_Return][1] GuiCtrlCreateLabel($Array[$Row_Return][2],200,13,140) Return $H_ComboBox EndFunc
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