Jump to content

new to combo/list boxes


aerb
 Share

Recommended Posts

Hi

am relative newb, and want to create a combo (or list) box, to select a value and pass to a variable. Have previously used a messy msgbox for this but want to tidy up. Have been trawling through various help files and forums but answers look over complicated.

e.g.

$Message="Please enter your location and click OK" & @LF & @LF & "an = Andover" & @lf & "be = Berwick" & @LF & "pu = Bockhampton" & @lf & "bo = Bourne" & @lf & "cr = Cranswick" & @lf & "di = Diss" & @LF & @LF

$bLoop = 1

While $bLoop = 1

$text = InputBox("Online Installer", $Message, "", " M2", 250, 330)

If @error = 1 Then

MsgBox(4100, "Error", "You pressed 'Cancel' - try again!")

Else

Select

Case $text = "an"

$answer = MsgBox(4, "Andover", "You typed in Andover! OK?")

$disks = "ITANDO"

If $answer = 6 Then

ExitLoop

EndIf

Case $text = "bo"

$answer = MsgBox(4, "Bourne", "You typed in Bourne! OK?")

$disks = "ITBOUR"

If $answer = 6 Then

ExitLoop

EndIf

Case $text = "be"

$answer = MsgBox(4, "Berwick", "You typed in Berwick! OK?")

$disks = "ITBERW"

If $answer = 6 Then

ExitLoop

EndIf

Case $text = "cr"

$answer = MsgBox(4, "Cranswick", "You typed in Cranswick! OK?")

$disks = "ITCRAN"

If $answer = 6 Then

ExitLoop

EndIf

Case $text = "di"

$answer = MsgBox(4, "Diss", "You typed in Diss! OK?")

$disks = "ITDISS"

If $answer = 6 Then

ExitLoop

EndIf

EndSelect

any help would be great, thanks

Edited by aerb
Link to comment
Share on other sites

looking for something like this?

[autoit]

#include <GUIConstantsEx.au3>

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

$Combo = GUICtrlCreateCombo("", 10, 10) ; create first item

GUICtrlSetData(-1, "Andover|Berwick|Bockhampton|Bourne|Cranswick|Diss") ; add other item snd set a new default

$n2 = GUICtrlCreateButton("Read",70,70,40,40)

GUISetState()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

If $msg= $n2 Then

If GUICtrlRead($Combo) = "Andover" Then

MsgBox(0,"","Test Andover")

EndIf

If GUICtrlRead($Combo) = "Berwick" Then

MsgBox(0,"","Test Berwick")

EndIf

If GUICtrlRead($Combo) = "Bockhampton" Then

MsgBox(0,"","Test Bockhampton")

EndIf

If GUICtrlRead($Combo) = "Bourne" Then

MsgBox(0,"","Test Bourne")

EndIf

If GUICtrlRead($Combo) = "Cranswick" Then

MsgBox(0,"","Test Cranswick")

EndIf

If GUICtrlRead($Combo) = "Diss" Then

MsgBox(0,"","Test Diss")

EndIf

EndIf

WEnd

[autoit]

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

  • Moderators

aerb,

Or you could rid of the If statements altogether like this: ;)

#include <guiconstantsex.au3>

$hGUI = GUICreate("My GUI combo")

$hCombo = GUICtrlCreateCombo("", 10, 10)
GUICtrlSetData(-1, "Andover|Berwick|Bockhampton|Bourne|Cranswick|Diss")
$hButton = GUICtrlCreateButton("Read", 70, 70, 40, 40)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hButton
            Switch GUICtrlRead($hCombo)
                Case "Andover"
                    MsgBox(0, "", "Test Andover")
                Case "Berwick"
                    MsgBox(0, "", "Test Berwick")
                Case "Bockhampton"
                    MsgBox(0, "", "Test Bockhampton")
                Case "Bourne"
                    MsgBox(0, "", "Test Bourne")
                Case "Cranswick"
                    MsgBox(0, "", "Test Cranswick")
                Case "Diss"
                    MsgBox(0, "", "Test Diss")
            EndSwitch
    EndSwitch
WEnd

Please ask if you have any questions. ;)

M23

P.S. When you post code please use Code tags. Put [autoit] before and [/autoit] after your posted code.

Edit: Just noticed this is my 10,000th post. :)

Edited by Melba23

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

Wow, congratulation to this amount of posts. Printed on paper it would be quite a big pile :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

P.S. When you post code please use Code tags. Put [autoit][/autoit] after your posted code.

Congrats Melba!!! when i replied, i used the tags but it did not works some times :) Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

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