Jump to content
Sign in to follow this  
gte

How to define values to a drop down box?

Recommended Posts

gte

I'm trying to assign values to items from a drop down menu, to write code so that if "AM" is chosen, a value is assigned to that and I can parse a time value into a cmd command without needing to alter it, and if "PM" is chosen, I can +12 the first part of the HH:MM:SS of the cmd file and then write it into the string

Here is the script I am working with, any thoughts?

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $msg
    
    GUICreate("My GUI") ; will create a dialog box that when displayed is centered

    GUICtrlCreateCombo("AM or PM?", 10, 10)

    GUICtrlSetData(-1, "AM|PM", 'AM or PM?')
    


    GUISetState()     ; will display an empty dialog box with a combo control with focus on

; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc  ;==>Example

Share this post


Link to post
Share on other sites
weaponx

Unfortunately the builtin combobox functions don't allow for key/value combinations.

Share this post


Link to post
Share on other sites
Valuater

What do you suggest then?

What's the point of having the combobox, if you can't code for values that are selected from it?

I think this is what you are looking to do!!

#include <GUIConstantsEx.au3>

GUICreate("My GUI") ; will create a dialog box that when displayed is centered
$combo = GUICtrlCreateCombo("AM or PM?", 10, 10)
GUICtrlSetData(-1, "AM|PM", 'AM or PM?')
GUISetState()

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop


    If $msg = $combo Then
        $cRead = GUICtrlRead($combo)
        If $cRead = "AM" Then
            MsgBox(4096, "Test", " You selected AM   ", 3)
        ElseIf $cRead = "PM" Then
            MsgBox(4096, "Test", " You selected PM   ", 3)
        EndIf
    EndIf

WEnd

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
weaponx

Honestly i'm not sure why it's like that, its a pain in the ass. I prefer the way they work in html.

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>

Dim $aData[3][2]

$aData[0][0] = "Red"
$aData[0][1] = "FF0000"
$aData[1][0] = "Green"
$aData[1][1] = "00FF00"
$aData[2][0] = "Blue"
$aData[2][1] = "0000FF"


$hGUI = GUICreate("My GUI combo",300,100)  ; will create a dialog box that when displayed is centered

$hCombo = GUICtrlCreateCombo("", 10, 10,"","",$CBS_DROPDOWNLIST)
;$hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 296, 20,$CBS_DROPDOWNLIST )

;Populate
For $X = 0 to Ubound($aData)-1
    GUICtrlSetData($hCombo,$aData[$X][0])
    ;_GUICtrlComboBox_AddString($hCombo,$aData[$X][0])
Next

$hButton = GUICtrlCreateButton("Retrieve Value",100,40,100)

GUISetState()

; Run the GUI until the dialog is closed
While 1
    Switch GUIGetMsg()
    
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hButton
            MsgBox(0,"",$aData[_GUICtrlComboBox_GetCurSel($hCombo)][1])
        
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Melba23

Val,

Could I offer a very slight change to your code to prevent the "AM or PM?" prompt becoming one of the choices in the combo:

#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>

GUICreate("My GUI"); will create a dialog box that when displayed is centered
$combo = GUICtrlCreateCombo("", 10, 10)
GUICtrlSetData(-1, "AM|PM")
_GUICtrlComboBox_SetEditText($combo, "AM or PM?")
GUISetState()


While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    If $msg = $combo Then
        $cRead = GUICtrlRead($combo)
        If $cRead = "AM" Then
            MsgBox(4096, "Test", " You selected AM   ", 3)
        ElseIf $cRead = "PM" Then
            MsgBox(4096, "Test", " You selected PM   ", 3)
        EndIf
        _GUICtrlComboBox_SetEditText($combo, "AM or PM?")
    EndIf

WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Valuater

Val,

Could I offer a very slight change to your code to prevent the "AM or PM?" prompt becoming one of the choices in the combo:

M23

Thanks Melba...

Actually that is a "Select" question by the OP. However, my script would not allow that as a selected choice..

^_^

8)

EDIT selection to selected

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
gte

Thanks all!

I'm about to venture into an area I don't even know where to start

#include <GUIConstantsEx.au3>
#Include <GuiComboBox.au3>

GUICreate("My GUI"); will create a dialog box that when displayed is centered
$combo = GUICtrlCreateCombo("", 10, 10)
GUICtrlSetData(-1, "AM|PM")
_GUICtrlComboBox_SetEditText($combo, "AM or PM?")
GUISetState()


While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    If $msg = $combo Then
        $cRead = GUICtrlRead($combo)
        If $cRead = "AM" Then
            $ampmvalue = '0'
            MsgBox(4096, "Test", " You selected AM   ", 3)
        ElseIf $cRead = "PM" Then
            $ampmvalue= '12'
            MsgBox(4096, "Test", " You selected PM   ", 3)
        EndIf
        _GUICtrlComboBox_SetEditText($combo, "AM or PM?")
    EndIf

WEnd


And then when they type in a time, say  10:11:12 (for the scheduled task), something will add the $ampmvalue to the first part of the time they type in (in this case 10) .

Any thoughts?

Share this post


Link to post
Share on other sites
TheLandYacht

Two questions about the script mentioned below. By the way, I've edited YOUR original script with a sample of the information I'm looking for.

1. In your example, you select an option in the dropdown menu, then click the RETRIEVE VALUE button to get the result. I am trying to design a similar drop-down menu for non-mouse use, so how would I change this to react to an enter-key press? In other words, use up/down arrows to select the menu item i want, then enter to display the result.

2. WHEN you hit the retrieve value button, it pops up a mini-window with the output. How would you change this to send the output as text to the program behind it(in this case, Cricket Wireless' text messaging software)?

These questions are because I am trying to build a simple phonebook for my Cricket Wireless network dongle's text messaging function. I'd like to keep a list of my most often used contacts in a dropdown, so i can just arrow down to the one I want, hit enter, & have the script paste the number into the appropriate field of the Cricket Wireless software.

Thanks in advance for any thoughts, and apologies in advance if I've hijacked the thread.

Honestly i'm not sure why it's like that, its a pain in the ass. I prefer the way they work in html.

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>

Dim $aData[3][2]

$aData[0][0] = "Joe Smith"
$aData[0][1] = "5125551212"
$aData[1][0] = "Jim Green"
$aData[1][1] = "5125553131"
$aData[2][0] = "Sally Fields"
$aData[2][1] = "5125556464"


$hGUI = GUICreate("My GUI combo",300,100)  ; will create a dialog box that when displayed is centered

$hCombo = GUICtrlCreateCombo("", 10, 10,"","",$CBS_DROPDOWNLIST)
;$hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 296, 20,$CBS_DROPDOWNLIST )

;Populate
For $X = 0 to Ubound($aData)-1
    GUICtrlSetData($hCombo,$aData[$X][0])
    ;_GUICtrlComboBox_AddString($hCombo,$aData[$X][0])
Next

$hButton = GUICtrlCreateButton("Retrieve Value",100,40,100)

GUISetState()

; Run the GUI until the dialog is closed
While 1
    Switch GUIGetMsg()
    
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hButton
            MsgBox(0,"",$aData[_GUICtrlComboBox_GetCurSel($hCombo)][1])
        
    EndSwitch
WEnd

Edited by TheLandYacht

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  

×