Sign in to follow this  
Followers 0
barryb

Populate Combo box from array

5 posts in this topic

Hi All,

been away from AutoIt for a while and I'm stuck trying to populate my dropdown combo box with data gathered in to an Array :graduated:

The code below parses all my removable media, but I need to be able to use this to populate my combo box but couldn't find any examples in the help,

I'm sure this is something really simple. but I can't get my head around how to do this, I'm sure it will be some type of For loop to add in each found drive in to the combo Box but I can't figure it out.

A friendly push in the right direction would be great.

Thanks,

Barry

Local $var = DriveGetDrive("REMOVABLE")
For $usb = 1 to $var[0]
MsgBox (0,"Drive", $var[$usb])
next

Share this post


Link to post
Share on other sites



Using Ubound() in a loop sounds like what you;re looking for


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

Thanks Shornw :graduated:

I will give that a try when I get a chance!

Cheers,

Barry

Share this post


Link to post
Share on other sites

Try this, it worked for me, although I substituted "NETWORK" for "REMOVABLE" for my test purposes.

#include <GUIConstantsEx.au3>
 
Local $var = DriveGetDrive("NETWORK")
GUICreate("Test", 230, 60)
$com = GUICtrlCreateCombo( "", 10, 10) ;Create combe
For $d = 1 To UBound($var) -1  ; Set data
GUICtrlSetData( -1, $var[$d] & "|")
Next
GuiSetState()
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
1 person likes this

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

Hi ShornW,

Turns out I was a complete nooblet and was over thinking this! I looked at what someone else had done for a similar issue and it was a lot easier than I thought :graduated: I just needed to use array to string

However this may or may not work for me so I will look at the code you created as well, as you can tell my test code is cut from the help lol ;)

Func Example()
Local $msg, $sDriveList
Local $var = DriveGetDrive("REMOVABLE")
$sDriveList = _ArrayToString($var, "|", 1) ; drives string
GUICreate("My GUI combo") ; will create a dialog box that when displayed is centered
GUICtrlCreateCombo("Select Drive", 10, 10) ; create first item
GUICtrlSetData(-1, $sDriveList, "") ; add other item snd set a new default
GUISetState()
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>Example

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