Jump to content

Get ComboBox Items and Count


Shibuya
 Share

Recommended Posts

need help with a function

tried it out but somehow it stopped midway

;==================================================================================================
;Function Name  :   _ControlComboBox()
;
;Description    :   Sends a command to a ComboBox control
;
;Parameter(s)   :   $cbTitle        - The title of the window to access
;                   $cbControlID    - The control to interact with
;                   $Switch         - The command to send to the control :
;
;Return(s)      :       - "GetItemCount"    - Returns the number of ComboBox items
;($Switch dependent)    - "GetItemList"     - Returns a array containing the list of items in the control
;                                           - Returns 0 if invalid switch
;==================================================================================================
Func _ControlComboBox($cbTitle, $cbControlID, $Switch)
    If $Switch = "" Then Return 0
    
    Local $cbListItems[101]
    Local $MaxCount = 0
    
    ControlSend($cbTitle, "", $cbControlID, "{HOME}")
    $cbListItems[1] = ControlCommand($cbTitle, "", $cbControlID, "GetCurrentSelection", "");get the first item
    
    $count = 2
    
    While 1
        ControlSend($cbTitle, "", $cbControlID, "{HOME}")
        ControlSend($cbTitle, "", $cbControlID, "{DOWN " & $count - 1 & "}")
        
        $cbListItems[$count] = ControlCommand($cbTitle, "", $cbControlID, "GetCurrentSelection", "");get the next item
        
        If $cbListItems[$count] = $cbListItems1][$count - 1] Then
            $cbListItems[$count] = ""
            $MaxCount = $count - 1
            
            $cbListItems[0] = $MaxCount; number of items
            
            ExitLoop
            
        EndIf
        
        $count = $count +1
        
    WEnd
    
    ReDim $cbListItems[$MaxCount + 1]
    
    If $Switch = "GetItemCount" Then
        Return $MaxCount
        
    ElseIf $Switch = "GetItemList" Then
        Return $cbListItems
        
    Else
        Return 0
    EndIf
    
EndFunc

anyone care to help me test this out to see what's wrong?

EDIT : changed from using a 2-dim array to a 1-dim

EDIT 2 : figured out the problem and fixed

EDIT 3 : any idea how to make this cleaner? I realised that if this function is used with a combobox which can initialise a pop-up, could fail the whole script

Edited by Shibuya

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

I digged the forums and found these:

ListBoxGetCount()

ListBox Madness

and noticed that the user32.dll - SendMessage command can actually peek into a ListBox

any idea if it can be done the same for a ComboBox?

I've looked into the MSDN Library over it and have absolutely no idea to start looking

Anyone who's familiar with this please help?

Edited by Shibuya

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

You might want to look at this thread http://www.autoitscript.com/forum/index.ph...ndpost&p=109731

if you decide to use the whole include file you'll need the beta, see my signature for link to it.

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

thanks gafrost!!!

found the _GUICtrlComboGetCount()

u mind poit out to me which one could get the list of the items?

if i guessed correctly, i probably have to do a loop for _GUICtrlComboGetLBText() to get the list, right?

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

thanks gafrost!!!

found the _GUICtrlComboGetCount()

u mind poit out to me which one could get the list of the items?

if i guessed correctly, i probably have to do a loop for _GUICtrlComboGetLBText() to get the list, right?

You got it.

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

damn I need help again

#include ".\Includes\GuiCombo.au3"

WinActivate("Display Properties")
WinWaitActive("Display Properties")

$hnd = ControlGetHandle("Display Properties", "", "ComboBox1")

$var = _GUICtrlComboGetCurSel($hnd)

MsgBox(0, "", $hnd)
MsgBox(0, "", $var)

can anyone tell me what's wrong with the above code?

I've tried it on the Display Properties window, using the Themes combobox to test it

I used the beta, no error codes on my SciTe editor other than the undefined IsHWnd(), which I think is because I haven't update my SciTe

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

Link to comment
Share on other sites

works for me, make sure your running in beta, either Alt+F5 or Tools, run beta

also you can add MsgBox(0,"Version",@AutoItVersion)

http://www.autoitscript.com/fileman/users/public/gafrost/combo1.JPGhttp://www.autoitscript.com/fileman/users/public/gafrost/combo2.JPG

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

sorry for the late reply

the UDF is working, just that I've used the wrong command

I should've used _GUICtrlGetLBText()

my bad B)

The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!"

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...