Hobbyist Posted December 30, 2014 Share Posted December 30, 2014 (edited) I am not asking for anybody to write script for this question. I AM asking for opinion or knowledge sharing on the approach. You all have much more experience at this. It is simply taking a 1D csv file and getting the file into a Combo. I thought of two methods - both are listed below #1 & #2. Does one make more sense? Any pitfalls? I can make them work, but what does the experience coder think is better and why. I get a lot of milage out of your explanations. Thanks. Hobbyist. local $ABC = (C:My File.csv) ;1D local $XYZ _FileReadToArray ( $ABC, $XYZ) For $i = 0 To UBound($XYZ,1) - 1 Next ;so the two different approaches are: 1.) $a = " " For $i = 0 To UBound($XYZ) - 1 $a &= $XYZ[$i] & "|" Next GUICtrlSetData($hcombo, $a) OR 2.) For $i = 0 To UBound($XYZ) - 1 _GUICtrlComboBox_InsertString ( $hcombo, $XYZ[$i]) Next Or on a resource basis this is just not a good idea? Edited December 30, 2014 by Hobbyist Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 31, 2014 Moderators Share Posted December 31, 2014 For long strings, I generally will use the 1 call method (your (1.) version). But that also depends if my control I'm going to populate is a standard autoit control or one from another app or created with _GUICtrl* functions. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
kylomas Posted December 31, 2014 Share Posted December 31, 2014 Can you post an example of your "1D csv file"??? 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...
Hobbyist Posted December 31, 2014 Author Share Posted December 31, 2014 Typical CVS file REDBOX *DVD RENTAL OAKBRKTERRACE IL REDBOX *DVDRESERVATION 866-733-2693 IL REDBOX DVD RENTAL 866-733-2693 IL AMAZON DIGITAL SVCS 866-216-1072 WA AMAZON MKTPLACE PMTS AMZN.COM/BILLWA AMAZON.COM AMZN.COM/BILL WA AMAZON.COM AMZN.COM/BILLWA SILPADA DESIGNS 913-8517757 KS Controls are all Autoit created and standard. Additional question does the _GUICtrlComboBox_InsertString method impact any sorting? Link to comment Share on other sites More sharing options...
jguinch Posted December 31, 2014 Share Posted December 31, 2014 Another way could be to put directly the whole content of the file, after replacing all carriage returns by "|" : $sContent = FileRead("csv.txt") $sContent = StringRegExpReplace($sContent, "\R+", "|") GUICtrlSetData($combo, $sContent) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Hobbyist Posted January 2, 2015 Author Share Posted January 2, 2015 Thanks for the reply and suggestions. Similar to one of the processes in my question and I tried sampling both - works great. Here is my example and question regarding the second option - using __GUICtrlComboBox_InsertString . Unlike option #1 or your suggestions, this option #2 does NOT sort the data in the Combo but rather just sequentially even though the Combo is set up for sorting. Or have I done something totally wrong here? If it means going to Guictrlsetdata that seems to be going back to option #1, or am I missing something? Or something more experienced coders know about with that method #2. Again thanks so much for taking time with my inexperience. I like to know the nuts and bolts. Hobbyist #include <Array.au3> #include <ComboConstants.au3> #include <GUIComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\Stoex\Autoit Trys\Vendors Trials\My combo Form Test.kxf $main = GUICreate("Test Screen", 680, 515, 150, 100) $hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25 , BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT,$CBS_UPPERCASE)) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) Dim $array_2[10] = ["","Nails", "Gas","Wood", "Misc", "Wire", "Vents","Cement","R-Bar","Tape"] _arraydisplay($array_2,"it") For $i = 0 To UBound($array_2) - 1 _GUICtrlComboBox_InsertString ( $hcombo, $array_2[$i]) Next While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 2, 2015 Moderators Share Posted January 2, 2015 http://msdn.microsoft.com/en-us/library/windows/desktop/bb775875(v=vs.85).aspx CB_INSERTSTRING message Inserts a string or item data into the list 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. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
kylomas Posted January 2, 2015 Share Posted January 2, 2015 (edited) Hobbyist, The simplest way to do this is as jguinch suggested... #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $main = GUICreate("Test Screen", 680, 515, 150, 100) $hcombo = GUICtrlCreateCombo("", 274, 26, 300, 25 , BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT, $CBS_UPPERCASE)) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) ; This is probably the simplest way to populate the combo control $sContent = FileRead(@scriptdir & "\combo.txt") $sContent = StringRegExpReplace($sContent, "\R+", "|") ; or if you are uncomfortable with SRE's use StringReplace *** will only work with EOL = CRLF whereas the SRE works with all EOL's ;$sContent = StringReplace($sContent, @CRLF, "|") GUICtrlSetData($hcombo, $sContent, filereadline(@scriptdir & '\combo.txt')) ; make the first line the default (file not sorted) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd combo.txt combo.txt contains the sample that you posted earlier. _GuiCtrlCombo_InsertString seems like it would be used after the combo box is populated and there is a need to insert something Not in sort sequence. Edited January 2, 2015 by 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...
Hobbyist Posted January 2, 2015 Author Share Posted January 2, 2015 Thanks to all 3 of you I have a more clear understanding of the issues in my question. I do apologize for having not seen the CB_ADDSTRING, having been myopic on the insertion route. While learning this script I'm hoping to get better at the "solutions approach" and simplicity. Again thanks and have a great 2015. Hobbyist 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