Sign in to follow this  
Followers 0
aerb

new to combo/list boxes

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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
1 person likes this

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

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

#5 ·  Posted (edited)

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]

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  
Followers 0