mrmacro Posted December 15, 2017 Share Posted December 15, 2017 (edited) Hi all some background info we have multiple client codes and i want , when each client code is selected from the combobox, to perform a slightly different action i am using the example from the help file for GUICtrlCreateCombo as a starting point and cant seem to work out how to get this to work for multiple clients (around 40). it always seems to read the first number and not the others. I have tried with and with out an if statement and cant get it to work (the if statement is commented out ) all specific data has been removed and shortened so it easier for you to read can some one look over this and point me in the right direction on a side note i did think about putting all the client codes in to an array and then referencing this further down as a number as in the code Send("{DOWN 1}") this will increase by 1 each the next client code is selected , but i dont understand arrays enough yet, even though reading the help file and other examples on here. i am sure it could be done but i am happy to get it working this way then will see if i can get it working as an array later once i understand more many thanks mrmacro expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Client Codes", 10, 10, 185, 20) Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "123|1234|12345") ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) ;~ MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI) WinWaitActive("Some website - Mozilla Firefox") Case $sComboRead = "123" ;~ If $sComboRead = "123" Then ;~ WinWaitActive("Some website - Mozilla Firefox") WinWaitActive("Some website - Mozilla Firefox") Sleep(5000) ;Selects the client Send("{SPACE}") Sleep(1500) Send("{DOWN 1}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send("{ENTER}") ;~ EndIf GUIDelete($hGUI) Exit Case $sComboRead = "1234" ;~ If $sComboRead = "1234" Then ;~ WinWaitActive("Some website - Mozilla Firefox") WinWaitActive("Some website - Mozilla Firefox") Sleep(5000) ;Selects the client Send("{SPACE}") Sleep(1500) Send("{DOWN 2}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send("{ENTER}") ;~ EndIf GUIDelete($hGUI) Exit Case $sComboRead = "12345" ;~ If $sComboRead = "12345" Then ;~ WinWaitActive("Some website - Mozilla Firefox") WinWaitActive("Some website - Mozilla Firefox") Sleep(5000) ;Selects the client Send("{SPACE}") Sleep(1500) Send("{DOWN 3}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send("{ENTER}") ;~ EndIf GUIDelete($hGUI) Exit EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Edited December 15, 2017 by mrmacro Link to comment Share on other sites More sharing options...
benners Posted December 15, 2017 Share Posted December 15, 2017 (edited) You need to put the conditional sComboRead values inside another switch\endswitch statement that runs when the combo box is selected. Quick example expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 300, 200) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Client Codes", 10, 10, 185, 20) Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "123|1234|12345") ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $sComboRead = "" ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Switch $sComboRead Case "123" MsgBox(0, '', '123') GUIDelete($hGUI) Exit Case "1234" MsgBox(0, '', '1234') GUIDelete($hGUI) Exit Case "12345" MsgBox(0, '', '12345') GUIDelete($hGUI) Exit EndSwitch EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example I'd personally use a function rather than fill up the while loop with 40 case statements. Check the help file for GUIOnEventMode and look at it's examples. Here's a small example expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Global $id_ComboBox = 0 DrawGUI() ; Loop until the user exits. While 1 sleep(50) WEnd Func DrawGUI() GUICreate("Client Codes", 300, 200) ; Create a GUI with various controls. GUISetOnEvent($GUI_EVENT_CLOSE, 'CloseProgram') $id_ComboBox = GUICtrlCreateCombo("", 10, 10, 185, 20) ; Create a combobox control. GUICtrlSetData(-1, "123|1234|12345") GUICtrlSetOnEvent(-1, 'ComboChange') GUICtrlCreateButton("Close", 210, 170, 85, 25) ; create a close button GUICtrlSetOnEvent(-1, 'CloseProgram') GUISetState(@SW_SHOW) ; Display the GUI. EndFunc ;==>Example Func CloseProgram() GUIDelete() exit EndFunc Func ComboChange() MsgBox(0,'Doing Something', GUICtrlRead($id_ComboBox)) CloseProgram() EndFunc Edited December 15, 2017 by benners Link to comment Share on other sites More sharing options...
mrmacro Posted December 15, 2017 Author Share Posted December 15, 2017 big thanks benners those examples give me an idea what i need to do i think i sort of realised i needed a loop within a loop but i was trying this with the if statements and not the case statements also i see that i was using for each case statement Case $sComboRead = "1234" when all i needed was Case = "1234" i will test this out and see how i get on mrmacro Link to comment Share on other sites More sharing options...
mrmacro Posted December 15, 2017 Author Share Posted December 15, 2017 (edited) 8 hours ago, mrmacro said: heres an update got it working , its currently 48 Case statements , but I just wanted it to work for now , I usually get it working first , then I find ways of making the code smaller and faster as time goes on but I will change this to a function or use the GUIOnEventMode as suggested from the help file, or look at arrays so I can load the combobox information , get the position of that info in the array and then use that in a function as a variable but you got me on the right track many thanks again mrmacro Edited December 15, 2017 by mrmacro Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now