SevereMessage

How can I read the data of a Combo?

14 posts in this topic

Trying to make sort of an incremental game for the lols, and here's my problem right now.

Keep in mind I'm a complete newbie at autoit, but I have a pretty good understanding of it, so go easy on me.

I have currently

$gems = GUICreate("Gem Seller", 219, 157, 887, 250)
$SellSelected = GUICtrlCreateButton("Sell Selected", 8, 40, 89, 25)
$Sellall = GUICtrlCreateButton("Sell all", 68, 96, 73, 25)

$Select = GUICtrlCreateCombo("Choose a Gem to sell!", 8, 8, 193, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$gemtype = GUICtrlSetData(-1, "Ruby|Emerald|Sapphire|Topaz|")

$status = _GUICtrlStatusBar_Create($gemtype)
_GUICtrlStatusBar_SetText($status, "You've selected: ")

I've added also a status bar

 

How can I read the data that GUICtrlSetData is selected? I tried

$selGUICtrlRead($gemtype) and it doesn't work.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

GUICtrlRead is fine. But you have to read the control. Means:

$sel = GUICtrlRead($Select)

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

GUICtrlRead is fine. But you have to read the control. Means:

$sel = GUICtrlRead($Select)

 

Sorry, I ment it, right now its laid out like this:

$gems = GUICreate("Gem Seller", 219, 157, 887, 250)
$SellSelected = GUICtrlCreateButton("Sell Selected", 8, 40, 89, 25)
$Sellall = GUICtrlCreateButton("Sell all", 68, 96, 73, 25)
$Select = GUICtrlCreateCombo("Choose a Gem to sell!", 8, 8, 193, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$gemtype = GUICtrlSetData(-1, "Ruby|Emerald|Sapphire|Topaz|")
$status = _GUICtrlStatusBar_Create($gemtype)
$input1 = GUICtrlRead($gemtype)
_GUICtrlStatusBar_SetText($status, "You've selected: " & $input1)

 

but it returns as 1, which I'm guessing is from the -1

 

Edit: or no, I followed the $select, but it displays "Choose a gem to sell" not the actual gems. 

 

How can I define what gem is what? I thought about maybe splitting the string?

Edited by SevereMessage

Share this post


Link to post
Share on other sites

Until you have not selected an item the default value is being returned.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Until you have not selected an item the default value is being returned.

I selected topaz for example, but it still returns 0?

 

Share this post


Link to post
Share on other sites

Is this the whole script you posted? You need to run a loop to wait until the control has been selected.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Is this the whole script you posted? You need to run a loop to wait until the control has been selected.

It's the only part that matters right now, the other parts are way too long and unnecessary, what can I add to make it work and how can I define the strings? 

Share this post


Link to post
Share on other sites

Something like this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Local $sComboRead = ""
Local $hGUI = GUICreate("Example", 300, 200)
Local $hComboBox = GUICtrlCreateCombo("Choose a Gem to sell!", 10, 10, 185, 20)
GUICtrlSetData($hComboBox, "Ruby|Emerald|Sapphire|Topaz")
Local $hClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)
GUISetState(@SW_SHOW, $hGUI)
; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hClose
            ExitLoop
        Case $hComboBox
            $sComboRead = GUICtrlRead($hComboBox)
            MsgBox($MB_SYSTEMMODAL, "", "You have selected: " & $sComboRead, 0, $hGUI)
    EndSwitch
WEnd

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Something like this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Local $sComboRead = ""
Local $hGUI = GUICreate("Example", 300, 200)
Local $hComboBox = GUICtrlCreateCombo("Choose a Gem to sell!", 10, 10, 185, 20)
GUICtrlSetData($hComboBox, "Ruby|Emerald|Sapphire|Topaz")
Local $hClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)
GUISetState(@SW_SHOW, $hGUI)
; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $hClose
            ExitLoop
        Case $hComboBox
            $sComboRead = GUICtrlRead($hComboBox)
            MsgBox($MB_SYSTEMMODAL, "", "You have selected: " & $sComboRead, 0, $hGUI)
    EndSwitch
WEnd

 

Ooh right, thank you very much, added in

_GUICtrlStatusBar_SetText($status, "You've selected: " & $Select2) in case and it works perfectly, next question how can I define Topaz, Ruby, etc?

Like

if GUiCtrlRead(Topaz)

Then

CheckAmount()

 

Share this post


Link to post
Share on other sites

What do you mean by "define"?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

What do you mean by "define"?

Like make them variables I guess?

I want to make it so whenever ruby for example is selected, and is clicked "SELL"

it runs a function, (Different function for each gem)

I'm guessing I would need to define it as a variable?

 

Share this post


Link to post
Share on other sites
Case $SellSelected ; When the Sell button is pressed check which item to sell.
    $sComboRead = GUICtrlRead($hComboBox)
    If $sComboRead = "xy" Then ...

Something like this?

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Case $SellSelected ; When the Sell button is pressed check which item to sell.
    $sComboRead = GUICtrlRead($hComboBox)
    If $sComboRead = "xy" Then ...

Something like this?

 

Aww yiss, thank you so much!

Share this post


Link to post
Share on other sites

Glad to be of service :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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