Jump to content
Sign in to follow this  
myxomatosii

Using A ComboBox To Declare Variables

Recommended Posts

myxomatosii

You can probably see what I'm trying to do here, use the Combo to set a variable.. but I've never created a (working) Combo before... lol.

Can someone please direct me as to why the GUI is automatically setting itself to 1?

Func getnum()
    GuiCreate("Ikariam",150,100)
    GuiCreate(@sw_show)
    GuiCtrlCreateCombo("",10,10,130,20)
    GuiCtrlSetData(-1,"One|Two|Three|Four|Five|Six|Seven|Eight|Nine")
    While 1
        Global $cits=0
        Local $msg=GuiGetMsg()
        Select
            Case $msg=$Gui_Event_Close
                GuiSetState(@sw_hide)
            Case $msg=GuiCtrlRead("One")
                $cits=1
            Case $msg=GuiCtrlRead("Two")
                $cits=2
            Case $msg=GuiCtrlRead("Three")
                $cits=3
            Case $msg=GuiCtrlRead("Four")
                $cits=4
            Case $msg=GuiCtrlRead("Five")
                $cits=5
            Case $msg=GuiCtrlRead("Six")
                $cits=6
            Case $msg=GuiCtrlRead("Seven")
                $cits=7
            Case $msg=GuiCtrlRead("Eight")
                $cits=8
            Case $msg=GuiCtrlRead("Nine")
                $cits=9
        EndSelect
        MsgBox(0,"",$cits,0)
    WEnd
EndFunc

Share this post


Link to post
Share on other sites
Achilles

Combo boxes do not activate a message (that I know of). That means that all your cases (except $msg = $GUI_EVENT_CLOSE) are never happening. What you want to do is also make a button, so that when you click the button it assigns a value to $cits. Do do that last part use this:

$cits = GUICtrlRead($combo)

But with that you also have to use this:

$combo = GuiCtrlCreateCombo("",10,10,130,20)

Instead of just saying GUICtrlCreateCombo...

A combo box has to have a value active in it (I think...), that's why it's getting set to one automatically.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
myxomatosii

Combo boxes do not activate a message (that I know of). That means that all your cases (except $msg = $GUI_EVENT_CLOSE) are never happening. What you want to do is also make a button, so that when you click the button it assigns a value to $cits. Do do that last part use this:

$cits = GUICtrlRead($combo)

But with that you also have to use this:

$combo = GuiCtrlCreateCombo("",10,10,130,20)

Instead of just saying GUICtrlCreateCombo...

A combo box has to have a value active in it (I think...), that's why it's getting set to one automatically.

Alrite, I'll try to change my approach.

Share this post


Link to post
Share on other sites
myxomatosii

Did this instead. Thanks for the redirection :P

#include <GUIConstantsEx.au3>
;AutoItSetOption("TrayIconHide",1)
Func getnum()
    Global $cits
    Local $b1,$b2,$b3,$b4,$b5,$b6,$b7,$b8,$cits=0
    GuiCreate("Ikariam",200,280)
    GuiSetState(@sw_show)
    GuiCtrlCreateLabel("How many cities do you have?",10,10)
    $b1=GuiCtrlCreateButton("One",10,40,80,20)
    $b2=GuiCtrlCreateButton("Two",10,65,80,20)
    $b3=GuiCtrlCreateButton("Three",10,90,80,20)
    $b4=GuiCtrlCreateButton("Four",10,115,80,20)
    $b5=GuiCtrlCreateButton("Five",10,140,80,20)
    $b6=GuiCtrlCreateButton("Six",10,165,80,20)
    $b7=GuiCtrlCreateButton("Seven",10,190,80,20)
    $b8=GuiCtrlCreateButton("Eight",10,215,80,20)
    $b9=GuiCtrlCreateButton("Nine",10,240,80,20)
    While 1
        Local $msg=GuiGetMsg()
        Select
            Case $msg=$b1
                $cits=1
                ExitLoop
            Case $msg=$b2
                $cits=2
                ExitLoop
            Case $msg=$b3
                $cits=3
                ExitLoop
            Case $msg=$b4
                $cits=4
                ExitLoop
            Case $msg=$b5
                $cits=5
                ExitLoop
            Case $msg=$b6
                $cits=6
                ExitLoop
            Case $msg=$b7
                $cits=7
                ExitLoop
            Case $msg=$b8
                $cits=8
                ExitLoop
            Case $msg=$b9
                $cits=9
                ExitLoop
            Case $msg=$Gui_Event_Close
                GuiSetState(@sw_hide)
        EndSelect
    WEnd
MsgBox(0,"",$cits,0)
EndFunc

Share this post


Link to post
Share on other sites
Achilles

Just so you can see how a combo would work in this scenario.

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>; <-- this has been added

;AutoItSetOption("TrayIconHide",1)
$cits = getnum()
Msgbox(0, '', $cits)

Func getnum()
    Global $cits
    GuiCreate("Ikariam", 170,70)
    GuiCtrlCreateLabel("How many cities do you have?",10,10)
    $combo = GUICtrlCreateCombo('', 10, 35, 100, 20, $CBS_DROPDOWNLIST) 
        GUICtrlSetData(-1, 'One|Two|Three|Four|Five|Six|Seven|Eight|Nine', 'One')
    GuiSetState(@sw_show)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
               ;GuiSetState(@sw_hide)
                ExitLoop
        EndSwitch
    WEnd
    $cits = GUICtrlRead($combo)
    GUIDelete()
    Return $cits
EndFunc

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
AdmiralAlkex

@Achilles

I get messages when a combo is used! Try this code and it will say "Two" if you select "Two" etc...

#include <GUIConstantsEx.au3>

getnum()

Func getnum()
    GuiCreate("Ikariam",150,100)
    GUISetState(@sw_show)
    $Combo = GuiCtrlCreateCombo("",10,10,130,20)
    GuiCtrlSetData(-1,"One|Two|Three|Four|Five|Six|Seven|Eight|Nine")
    While 1
        Global $cits=0
        Local $msg=GuiGetMsg()
        Select
            Case $msg=$Gui_Event_Close
                GuiSetState(@sw_hide)
            Case $msg=$Combo
                $cits=GuiCtrlRead($Combo)
                MsgBox(0,"",$cits,0)
        EndSelect
    WEnd
EndFunc

Share this post


Link to post
Share on other sites
Achilles

@Achilles

I get messages when a combo is used! Try this code and it will say "Two" if you select "Two" etc...

#include <GUIConstantsEx.au3>

getnum()

Func getnum()
    GuiCreate("Ikariam",150,100)
    GUISetState(@sw_show)
    $Combo = GuiCtrlCreateCombo("",10,10,130,20)
    GuiCtrlSetData(-1,"One|Two|Three|Four|Five|Six|Seven|Eight|Nine")
    While 1
        Global $cits=0
        Local $msg=GuiGetMsg()
        Select
            Case $msg=$Gui_Event_Close
                GuiSetState(@sw_hide)
            Case $msg=$Combo
                $cits=GuiCtrlRead($Combo)
                MsgBox(0,"",$cits,0)
        EndSelect
    WEnd
EndFunc
That's what it's supposed to do.... And then he can easily convert that to an actual number using a switch. Come to think of it, a GUICtrlCreateUpdown would probably work better...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

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  

×