Jump to content

Using Combobox Information When Clicking A Button


Recommended Posts

I am trying to use the selection in a combo box to determine what a button does. This is my code thus far:

#include <GuiConstants.au3>

Opt('GUIOnEventMode', 1)
Opt("TrayIconHide", 1)

Global $region
Global $selected

GuiCreate("Gui", 400, 350)
GuiSetIcon("icon.ico")
GUISetOnEvent($GUI_EVENT_CLOSE, 'Event_GUIClose')

GUICtrlCreateButton("Button", 100, 170, 200, 30)
GUICtrlSetOnEvent(-1, 'function')

$region = GUICtrlCreateCombo("", 130, 310, 150, 120, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "item1|item2|item3|item4|item5","item2")
$selected = GuiCtrlRead($region)

Func function()
    
GUISetState(@SW_HIDE)
If $selected = "item1" or "item2" or "item3" Then
    Run("program1.exe")
ElseIf $selected = "item4" Then
    Run("program2.exe")
ElseIf $selected = "item5" Then
    Run("program3.exe")
EndIf
Exit
EndFunc

GUISetState(@SW_SHOW)

While 1
    Sleep(250)
WEnd

Func Event_GUIClose()
    
    Exit
    
EndFunc

I don't receive any errors, but nomatter what is selected in the combo box it always runs program1.exe.

Thanks!

Edited by Airwolf123
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

no-no

If $selected = "item1" or "item2" or "item3" Then

try this

If $selected = "item1" or $selected = "item2" or $selected = "item3" Then

plus you'll want to move this just above that line

$selected = GuiCtrlRead($region)
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • Moderators

no-no

If $selected = "item1" or "item2" or "item3" Then

try this

If $selected = "item1" or $selected = "item2" or $selected = "item3" Then

plus you'll want to move this just above that line

$selected = GuiCtrlRead($region)
gafrost is exactly right, but if you use the beta version you could go at it this way:

#include <GuiConstants.au3>

Opt('GUIOnEventMode', 1)
Opt("TrayIconHide", 1)

GUICreate("Gui", 400, 350)
GUISetIcon("icon.ico")
GUISetOnEvent($GUI_EVENT_CLOSE, 'Event_GUIClose')

GUICtrlCreateButton("Button", 100, 170, 200, 30)
GUICtrlSetOnEvent(-1, 'function')

$region = GUICtrlCreateCombo("", 130, 310, 150, 120, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "item1|item2|item3|item4|item5", "item2")

GUISetState(@SW_SHOW)

While 1
    Sleep(250)
WEnd

Func function() 
    $selected = GUICtrlRead($region)
    GUISetState(@SW_HIDE)
    Switch $selected
        Case "item1", "item2", "item3"
            Run("program1.exe")
        Case "item4"
            Run("program2.exe")
        Case "item5"
            Run("program3.exe")
    EndSwitch
    Exit
EndFunc  ;==>function

Func Event_GUIClose()   
    Exit    
EndFunc  ;==>Event_GUIClose
Link to comment
Share on other sites

no-no

If $selected = "item1" or "item2" or "item3" Then

try this

If $selected = "item1" or $selected = "item2" or $selected = "item3" Then

plus you'll want to move this just above that line

$selected = GuiCtrlRead($region)
That worked great! Thanks!
Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
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...