Sign in to follow this  
Followers 0
Hobbyist

Populate Combo

9 posts in this topic

#1 ·  Posted (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 by Hobbyist

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0