Sign in to follow this  
Followers 0
Venix

Help Me With _GUICtrlComboBoxEx_GetCurSel

9 posts in this topic

Hello, i am still fairly new to AutoIt and i need help using the _GUICtrlComboBoxEx_GetCurSel function, the reason i want to use this function is to return the numeric value of the currently selected item in a combo box. I am not sure if i am using the wrong function to achieve this but even after reading the help file i cant figure out what is wrong with my code. At the moment the value is always being returned as 3 no matter what is selected.

Heres My Code, Please let me know what i am doing wrong :oops:.

;Currently not functioning, purely for testing reasons.
#include <GuiComboBoxEx.au3>
#include <GuiComboBox.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test", 226, 278, 192, 124)
$Combo = GUICtrlCreateCombo("", 8, 8, 209, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Data = GUICtrlSetData(-1, "Derp|Herp|Ferp|Kerp|Pizza")
$List1 = GUICtrlCreateList("", 8, 32, 209, 201)
$Button1 = GUICtrlCreateButton("", 8, 240, 209, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                            Exit
       Case $Button1
        _GUICtrlComboBoxEx_GetCurSel($Combo)
                            msgbox(0, "Test", $Combo)
    
            EndSwitch
    WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Modified part of the code seen a possible error but now just returns as 0.

Case $Button1
                            msgbox(0, "Test",  _GUICtrlComboBoxEx_GetCurSel($Combo))
Edited by Venix

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this:

;Currently not functioning, purely for testing reasons.
#include <guicomboboxex.au3>
#include <guicombobox.au3>
#include <constants.au3>
#include <buttonconstants.au3>
#include <comboconstants.au3>
#include <guiconstantsex.au3>
#include <guilistbox.au3>
#include <windowsconstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test", 226, 278, 192, 124)
$Combo = GUICtrlCreateCombo("", 8, 8, 209, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
$Data = GUICtrlSetData(-1, "Derp|Herp|Ferp|Kerp|Pizza")
$List1 = GUICtrlCreateList("", 8, 32, 209, 201)
$Button1 = GUICtrlCreateButton("", 8, 240, 209, 33)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Global $test = _GUICtrlComboBoxEx_GetCurSel(GUICtrlGetHandle($Combo)) ; <<< You need to use the handle of the control, and you need to read the return from the function call
            MsgBox(0, "Test", $test)

    EndSwitch
WEnd
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thank you works perfectly I am suprised that all it wanted me to do was call a variable.

Share this post


Link to post
Share on other sites

I was just taking a relook at this code, and if you had used _GUICtrlComboBox_GetCurSel($Combo) instead of _GUICtrlComboBoxEx_GetCurSel($Combo) it would have worked as well and you wouldn't have needed to use GUICtrlGetHandle with $Combo.

Unless you actually need to use the _GUICtrlComboBoxEx_* functions, there's no need to use them as I believe the non-Ex combobox UDF has all the same functions. The _GUICtrlComboBoxEx_* functions should only need to be used when using a ComboBoxEx type of combobox, which is, basically, an enhanced type of ComboBox.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

_GUICtrlComboBoxEx is one of those that doesn't convert the controlID to a handle if a controlid is in fact passed and for good reason too, since _GUICtrlComboBoxEx should ideally be used with a combobox created with _GUICtrlComboBoxEx_Create.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Is there a way to use _GUICtrlComboBoxEx_GetCurSel mid switch/case statement for the sake of fullfilling an action when an item in the comboBox_EX is selected?

Such as:

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $readComboC = _GUICtrlComboBoxEx_GetCurSel($Combo1)
    switch $readComboC
     case 1
      ; clear the list before loading the macro list
      _GUICtrlListBox_ResetContent($hListBox)
      ; Add strings
      _GUICtrlListBox_BeginUpdate($hListBox)
      _GUICtrlListBox_AddString($hListBox, "New")
      For $iI = 1 To $listArray[0][0]
       _GUICtrlListBox_AddString($hListBox, $listArray[$iI][1])
      Next
      _GUICtrlListBox_EndUpdate($hListBox)
     case 2
      ; clear the list before loading the macro list
      _GUICtrlListBox_ResetContent($hListBox)
      MsgBox(0x40000, "", "fail")
    EndSwitch
EndSwitch

So far this doesn't work, but I'm just wondering if I am doing it wrong based on what has been noted in this thread thus far.

Share this post


Link to post
Share on other sites

You're using the Switch case wrong, $nMsg is going to equal the control that is being activated, your case statement will never match because you're comparing the control with its contents. Your Case statement should read something like this:

Case $Combo1
    $readcomboc = _GUICtrlComboBoxEx_GetCurSel($Combo1)
    switch $readComboC

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yeah as soon as I posted it it hit me..started testing some code and came up with this snippet from the total test program which I will post on the original thread I had, but someone may find this tidbit useful:

While 1
$comboText = ControlGetText($hMain, "", "[CLASS:Edit; INSTANCE:1]")
if $comboText <> $placeholder Then
  $placeholder = $comboText
Switch $comboText
  case "Macro 1"
   $macro1Array = ""
   $macro1Array = IniReadSection("testMacro1.ini", "itemlist")
   ; clear the list before loading the macro list
   _GUICtrlListBox_ResetContent($hListBox)
   ; Add strings
   _GUICtrlListBox_BeginUpdate($hListBox)
   _GUICtrlListBox_AddString($hListBox, "New")
   For $iI = 1 To $macro1Array[0][0]
    _GUICtrlListBox_AddString($hListBox, $macro1Array[$iI][1])
   Next
   _GUICtrlListBox_EndUpdate($hListBox)
  case "Macro 2"
   $macro2Array = ""
   $macro2Array = IniReadSection("testMacro2.ini", "itemlist")
   ; clear the list before loading the macro list
   _GUICtrlListBox_ResetContent($hListBox)
   ; Add strings
   _GUICtrlListBox_BeginUpdate($hListBox)
   _GUICtrlListBox_AddString($hListBox, "New")
   For $iI = 1 To $macro2Array[0][0]
    _GUICtrlListBox_AddString($hListBox, $macro2Array[$iI][1])
   Next
   _GUICtrlListBox_EndUpdate($hListBox)

  case "New"
   ; clear the list before loading the macro list
   _GUICtrlListBox_ResetContent($hListBox)
   MsgBox(0x40000, "", "Create a new macro...")
EndSwitch
EndIf

$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $saveBTN
;~   MsgBox(0x40000, "", $comboText)
   switch $comboText
    case "New"
     MsgBox(0x40000, "New Macro", "Create a new macro in the .ini files...")
    Case "Macro 1"
     ; Select a few items
     $x = _GUICtrlListBox_SelItemRange($hListBox, 1, $listArray[0][0])
     if $x = True Then
      $listRearrange = _GUICtrlListBox_GetSelItemsText($hListBox)
;~     _ArrayDisplay($listRearrange)
       For $xL = 1 to $listRearrange[0]
        IniWrite("testMacro1.ini", "itemlist", $xL, $listRearrange[$xL])
       Next
     Else
      Sleep(100)
     EndIf
    case "Macro 2"
     ; Select a few items
     $x = _GUICtrlListBox_SelItemRange($hListBox, 1, $listArray[0][0])
     if $x = True Then
      $listRearrange = _GUICtrlListBox_GetSelItemsText($hListBox)
;~     _ArrayDisplay($listRearrange)
       For $xL = 1 to $listRearrange[0]
        IniWrite("testMacro2.ini", "itemlist", $xL, $listRearrange[$xL])
       Next
     Else
      Sleep(100)
     EndIf
   EndSwitch

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