Jump to content

Multiple choice input box


paul1149
 Share

Recommended Posts

Hi,

Sorry for what I suspect is a simple question. I have a script (see below) by which I switch Power Plans in Win7. It opens an InputBox, I type in the number of the plan that I want and click OK. It works fine.

But I'd like to expand the box and add more options, and I'd like to 1) clean up the options presentation, one option per line, and 2) possibly assign each option to a Control Button.

Is something like this possible?

Thanks,

p.

The existing script:

$PowerPlan = InputBox( "Choose Power Plan", "1: Energy Star, 2: myNoSleep" )

If $PowerPlan = 1 Then

Run("Powercfg -setactive c0ea6ad3-6145-4447-a15e-5fb97be69b98")

Exit

Else

Run("powercfg -setactive c78a5555-aa90-40c0-a554-20788489c55b")

Exit

EndIf

Link to comment
Share on other sites

  • Moderators

paul1149,

Sounds like you need a combo: :graduated:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData(-1, "Energy Star|myNoSleep")

GUISetState()

$sCurrCombo = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            If GUICtrlRead($hCombo) <> $sCurrCombo Then
                $sCurrCombo = GUICtrlRead($hCombo)
                MsgBox(0, "Choice", $sCurrCombo)
            EndIf
    EndSwitch

WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

paul1149,

Is it possible to list the options openly, one per line, with a control button for each one?

If that is all you want, just create a GUI with buttons and associated labels. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

M23 appears to be asleep at the wheel today. I think he probably meant use RADIO buttons and read the value of those when a Control button is clicked.

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hRadio_1 = GUICtrlCreateRadio("Energy Star", 10, 10, 100, 20)
$hRadio_2 = GUICtrlCreateRadio("My No Sleep", 10, 30, 100, 20)
$hRadio_3 = GUICtrlCreateRadio("My Other Scheme", 10, 60, 100, 20)
$hBtn_Go = GUICtrlCreateButton("Set", 220, 420, 60, 25)
GUISetState()

$sText = ""

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hBtn_Go
            For $i = $hRadio_1 To $hRadio_3
                If GUICtrlRead($i) = 1 Then
                    $sText = GUICtrlRead($i, 1)
                    MsgBox(0, "Choice", $sText)
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

Less of the cheek - I do have other things to do in my life you know! :(

Actually I forgot to log off! :D

paul1149,

George was not able to read my mind this time - what I actually had in mind was something like this: :graduated:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

GUICtrlCreateLabel("Energy Star", 100, 15, 100, 20)
GUICtrlCreateLabel("My No Sleep", 100, 55, 100, 20)
GUICtrlCreateLabel("My Other Scheme", 100, 95, 100, 20)

$hButton_1 = GUICtrlCreateButton("Go", 10, 10, 80, 30)
$hButton_2 = GUICtrlCreateButton("Go", 10, 50, 80, 30)
$hButton_3 = GUICtrlCreateButton("Go", 10, 90, 80, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton_1
            MsgBox(0, "Choice", "Energy Star")
        Case $hButton_2
            MsgBox(0, "Choice", "My No Sleep")
        Case $hButton_3
            MsgBox(0, "Choice", "My Other Scheme")
    EndSwitch
WEnd

As you can see, there are many ways to skin this particular feline. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

M23 and GEO,

Wow - sorry. I had a file mix-up. Somehow the file I was working on in the editor was not the file I was executing from Desktop. Once I got that straightened out these scripts work perfectly. This button one is exactly what I was looking for. Thanks much to both of you for your time on this!

Thanks,

p.

Link to comment
Share on other sites

Darn!!!! M23 wins again. I'll settle that issue on the next one.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 4 years later...
  • Moderators

SpecialS,

Put the loop inside a function which you call when the button is actioned? Without more details I cannot really offer anything more sensible.

M2£

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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