Jump to content

ComboBox to array?


 Share

Recommended Posts

Couldn't find an answer from previous topics to how can I get the elements from a combobox into an array? If someone has a valid function or something, it would be very helpful!

-juk

Link to comment
Share on other sites

Beta version

Retrieve a string from the list of a combo box.

#Include <GuiCombo.au3>

_GUICtrlComboGetLBText($h_combobox, $i_index, ByRef $s_text)

<{POST_SNAPBACK}>

I didn't even know about the beta versions, thanks!

Now I've got the 3.1.1.55 beta version, but it's not working for me:

#include <GuiConstants.au3>
#include <GuiCombo.au3>

opt("WinTitleMatchMode",2)
If Not WinActive("My Computer","") Then WinActivate("My Computer","")
WinWaitActive("My Computer","")

$i=0
Global $s_text
While 1
    $i_count = _GUICtrlComboGetLBText(41477, $i, $s_text)
    if $i_count == -1 Then
        ExitLoop
    EndIf
    MsgBox(0,"","length: " & $i_count&", text: " & $s_text)
    $i=$i+1
WEnd

There I've tried to get the elements from the explorer's combobox (control id 41447) and show them in a msgbox, but this just doesn't work! Msgbox shows zero (0) for both $i_count and $s_text each time and all the time. The variable $i works just fine.

I've tried to get the insides of comboboxes from different windows aswell, but never succeeded. Has anyone got a working solution to this?

-juk

Link to comment
Share on other sites

1st

$i_count = _GUICtrlComboGetLBText(41477, $i, $s_text

and

combobox (control id 41447)

which is correct????

also, this is not my specialty, but ...

you are trying to read a window (my Computer)... not an actual combo box

and

quote" how can I get the elements from a combobox into an array?"

However, you appear to be working with a $string not an $array[0].. there is a major difference

lastly

nice try

8)

NEWHeader1.png

Link to comment
Share on other sites

The UDFs only work with the GUI ComboBox, didn't write them for the system wide combobox's, if you need to access a ComboBox outside of the AutoIt GUI

you'll need to learn about the DllCall function, also you'll have to research the ComboBox control, SendMessage at MSDN.

Here's an example of getting all the items from a AutoIt GUI ComboBox and putting them into an array.

#include <GuiConstants.au3>
#include <GuiCombo.au3>
#include <Array.au3>

opt('MustDeclareVars', 1)

Dim $Combo, $ret, $Btn_Exit, $Status, $msg, $Btn_Get, $Btn_Show, $a_ComboList, $i, $i_count, $s_text

GUICreate("ComboBox Get Count", 392, 254)

$Combo = GUICtrlCreateCombo("", 70, 10, 270, 100, $CBS_SIMPLE)
$ret = _GUICtrlComboAddDir ($Combo, "drives")
$Btn_Get = GUICtrlCreateButton("Get Text", 150, 120, 90, 30)
$Btn_Show = GUICtrlCreateButton("Show Array", 150, 160, 90, 30)
$Btn_Exit = GUICtrlCreateButton("Exit", 150, 200, 90, 30)
$Status = GUICtrlCreateLabel("", 0, 234, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))
GUICtrlSetData($Status, "Items in ComboBox: " & _GUICtrlComboGetCount ($Combo))
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Btn_Get
            For $i = 0 To _GUICtrlComboGetCount ($Combo) - 1
                $i_count = _GUICtrlComboGetLBText ($Combo, $i, $s_text)
                If IsArray($a_ComboList) Then
                    ReDim $a_ComboList[UBound($a_ComboList) + 1]
                Else
                    Dim $a_ComboList[1]
                EndIf
                $a_ComboList[UBound($a_ComboList) - 1] = $s_text
            Next
        Case $msg = $Btn_Show
            _ArrayDisplay($a_ComboList, "Combobox Items")
    EndSelect
WEnd
Exit
Edited 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.

 

Link to comment
Share on other sites

1st

$i_count = _GUICtrlComboGetLBText(41477, $i, $s_text

and

combobox (control id 41447)

which is correct????

Ok, I made a typo in the text, but it was right in the code. :)

also, this is not my specialty, but ...

you are trying to read a window (my Computer)... not an actual combo box

I'm trying to read a combobox in a window (they usually are inside windows, right?) which happens to be explorer (My Computer). I tried it with various different softwares' windows' comboboxes also (acrobat reader, ms paint, you name it). All failed.

and

quote" how can I get the elements from a combobox into an array?"

However, you appear to be working with a $string not an $array[0].. there is a major difference

<{POST_SNAPBACK}>

That was my original idea, but mr. gafrost presented a similiar solution (combobox to string) so I started working with that.

-juk

Link to comment
Share on other sites

The UDFs only work with the GUI ComboBox, didn't write them for the system wide combobox's, if you need to access a ComboBox outside of the AutoIt GUI

you'll need to learn about the DllCall function, also you'll have to research the ComboBox control, SendMessage at MSDN.

<{POST_SNAPBACK}>

Ah, so that's it! I'm still new at this so couldn't figure it out. Thanks!

I found some dllcall, from previous posts, that counted elements in a combo, but am still looking for one that gives them in an array. Tried to search MSDN also, but it seemed like an ocean of useless information (for me). Maybe I just gotta look harder...

-juk

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...