mrmacro Posted December 19, 2017 Share Posted December 19, 2017 (edited) hi all hope this is the correct portion of the forum? I posted previously and had help on my project Combobox example modification brief outline of what I am now trying to do to be able to get the information selected from a combobox into a $variable1 and then to get the position off $variable1 and put this position in to $variable2 to be able to use both variables further on in the code instead of using 48 case statements (this does work but I guess its a little longwinded) using variables would make this in to only 1 statement I hope code below (removed 47 case statements but hope you get the idea) expandcollapse popupSelectClientCode() Func SelectClientCode() ;~ ; Create a GUI with various controls. Local $hGUI = GUICreate("Client Codes", 250, 50) ;~ ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Select Client Code", 10,15, 185, 20) Global $idComboBox = "" ; Add additional items to the combobox. GUICtrlSetData($idComboBox, "5155|7065|7071|B304|B344|B380|B390|B415|B416|B423|B471|B486|B518|B524|B525|B531|B580|B618|B619|B620|B635|B636|B642|B644|B645|B656|B657|B688|B689|B693|B714|B715|B749|B755|B756|B790|B793|B797|B805|B808|B819|B833|B845|B846|I432|I433|W006|W034") ; 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 "5155" ;~ WinWaitActive("SecureSync - Mozilla Firefox") WinActivate("SecureSync - Mozilla Firefox") Sleep(5000) ;Selects the client Send("{SPACE}") Sleep(1500) Send("{DOWN 1}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send("{ENTER}") GUIDelete($hGUI) Exit EndSwitch EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>SelectClientCode #Region SelectClientCode I have been trying to understand Arrays , and using the help file example of _ArraySearch and _ArrayToString but they have fried my brain I have managed to get the position of the client code using another example from the help file Local $iMax Local $cCode = "5155|7065|7071|B304|B344|B380|B390|B415|B416|B423|B471|B486|B518|B524|B525|B531|B580|B618|B619|B620|B635|B636|B642|B644|B645|B656|B657|B688|B689|B693|B714|B715|B749|B755|B756|B790|B793|B797|B805|B808|B819|B833|B845|B846|I432|I433|W006|W034" ; The string in data will be split into an array everywhere | is encountered Local $arr = StringSplit($cCode, "|") ;~ had to hard code this as i dont yet know how to get it to work Global $theCC = '5155' ;~ _ArrayDisplay($arr, "", Default, 8) $row = _ArraySearch($arr, $theCC, "", "", "", "", 1) MsgBox(0, "The Clientcode", $theCC) MsgBox(0, "The row", $row) so that I could replace Case "5155" with case $variable1 and Send("{DOWN 1}") with Send("{DOWN [$varable2]}") so allowing me to use the position in the array But I have to concede to asking for some help mrmacro Edited December 19, 2017 by mrmacro Link to comment Share on other sites More sharing options...
kylomas Posted December 20, 2017 Share Posted December 20, 2017 (edited) mrmacro, Why do you do send('{down 1}')? kylomas edit: if it helps, you can read the entire combo box list...if you can explain what you want there is a better way than a bunch of case stmt's...I read your other thread and still don't get your goal... edit2: this is from your previous thread... Quote get the position of that info in the array and then use that in a function as a variable not sure what you are trying to do... edit3: An example of using an array with a combo box... expandcollapse popup#include <array.au3> #include <GuiConstants.au3> Local $aClientCodes[50] = ['5155', '7065', '7071', 'B304', 'B344', 'B380', 'B390', 'B415', 'B416', 'B423', 'B471', 'B486', _ 'B518', 'B524', 'B525', 'B531', 'B580', 'B618', 'B619', 'B620', 'B635', 'B636', 'B642', 'B644', 'B645', 'B656', 'B657', 'B688', _ 'B689', 'B693', 'B714', 'B715', 'B749', 'B755', 'B756', 'B790', 'B793', 'B797', 'B805', 'B808', 'B819', 'B833', 'B845', 'B846', 'I432', 'I433', 'W006', 'W034'] SelectClientCode() Func SelectClientCode() ;~ ; Create a GUI with various controls. Local $hGUI = GUICreate("Client Codes", 250, 50) ;~ ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Select Client Code", 10, 15, 185, 20) ; ; populate the combo control with the contents of the client array...default delimiter must be "|" (it is unless you change it) ; Third parameter sets the initial value for the edit portion of the combo control ; GUICtrlSetData($idComboBox, _ArrayToString($aClientCodes), $aClientCodes[0]) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ;Local $sComboRead = "" ; this is created in local scope as the return from function GuiCtrlRead ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Switch $sComboRead Case "5155" ;~ WinWaitActive("SecureSync - Mozilla Firefox") ; ; this is where you lose me...you are sending a space, down 1 and two enters to a web site, or whatever the currently active window is... ; WinActivate("SecureSync - Mozilla Firefox") Sleep(5000) ;Selects the client Send("{SPACE}") Sleep(1500) Send("{DOWN 1}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send("{ENTER}") GUIDelete($hGUI) Exit EndSwitch EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>SelectClientCode #Region SelectClientCode One last thing, think of a 1d array as a list. You access the list using the variable name ($aClientCodes) and an index starting at 0 in brackets. So to get the third entry of your array you can do local $MyThirdEntry = $aClientList[2] Edited December 20, 2017 by kylomas mrmacro 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
benners Posted December 20, 2017 Share Posted December 20, 2017 (edited) 15 hours ago, mrmacro said: I have managed to get the position of the client code using another example from the help file There's no need to use _ArraySearch in this case. If you make sure that the codes in the array match the position in the combo you can do it this way expandcollapse popup#include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $cCode = "5155|7065|7071|B304|B344|B380|B390|B415|B416|B423|B471|B486|B518|B524|B525|B531|B580|B618|B619|B620|B635|B636|B642|B644|B645|B656|B657|B688|B689|B693|B714|B715|B749|B755|B756|B790|B793|B797|B805|B808|B819|B833|B845|B846|I432|I433|W006|W034" ; The string in data will be split into an array everywhere | is encountered Global $arr = StringSplit($cCode, "|") SelectClientCode() Func SelectClientCode() ;~ ; Create a GUI with various controls. Local $hGUI = GUICreate("Client Codes", 250, 50) ;~ ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Select Client Code", 10, 15, 185, 20) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, $cCode) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $i_Index = 0 ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idComboBox ; get the index of the currently selected item (starts at 0) $i_Index = _GUICtrlComboBox_GetCurSel($idComboBox) MsgBox(0, 'array position: ' & $i_Index, 'Array Value: ' & $arr[$i_Index]) EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>SelectClientCode #Region SelectClientCode In Send("{DOWN 1}"), if the number in red increments by one, you could also use try using $i_Index for the number. (untested) expandcollapse popup#include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $cCode = "5155|7065|7071|B304|B344|B380|B390|B415|B416|B423|B471|B486|B518|B524|B525|B531|B580|B618|B619|B620|B635|B636|B642|B644|B645|B656|B657|B688|B689|B693|B714|B715|B749|B755|B756|B790|B793|B797|B805|B808|B819|B833|B845|B846|I432|I433|W006|W034" ; The string in data will be split into an array everywhere | is encountered Global $arr = StringSplit($cCode, "|") SelectClientCode() Func SelectClientCode() ;~ ; Create a GUI with various controls. Local $hGUI = GUICreate("Client Codes", 250, 50) ;~ ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("Select Client Code", 10, 15, 185, 20) ; Add additional items to the combobox. GUICtrlSetData($idComboBox, $cCode) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Local $i_Index = 0 ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idComboBox ; get the index of the currently selected item (starts at 0) $i_Index = _GUICtrlComboBox_GetCurSel($idComboBox) MsgBox(0, 'array position: ' & $i_Index, 'Array Value: ' & $arr[$i_Index]) WinActivate("SecureSync - Mozilla Firefox") Sleep(5000) ;Selects the client Send("{SPACE}") Sleep(1500) Send("{DOWN " & $i_Index & "}") ; untested Sleep(1500) Send("{ENTER}") Sleep(1500) Send("{ENTER}") GUIDelete($hGUI) Exit EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>SelectClientCode #Region SelectClientCode Edited December 20, 2017 by benners mrmacro 1 Link to comment Share on other sites More sharing options...
benners Posted December 20, 2017 Share Posted December 20, 2017 Here's an example of reading the codes from a file. That way if the codes change you don't need to keep altering the main script expandcollapse popup#include <Array.au3> #include <File.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; read the codes from the file. Saves hard coding into the script Global $as_ClientCodes = FileReadToArray(@ScriptDir & '\ClientCodes.txt') ; check for an array before using and exit if issues If Not IsArray($as_ClientCodes) Then Exit (MsgBox($MB_ICONERROR, 'Error', 'Unable to read the client codes')) SelectClientCode() Func SelectClientCode() ; Create a GUI with various controls. Local $hGUI = GUICreate("Client Codes", 250, 50) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo('', 10, 15, 185, 20) GUICtrlSetData(-1, _ArrayToString($as_ClientCodes)) ; add the client codes _GUICtrlComboBox_SetCurSel($idComboBox, 0) ; set the first item Local $i_Index = 0 ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idComboBox ; get the index of the currently selected item (starts at 0) $i_Index = _GUICtrlComboBox_GetCurSel($idComboBox) If Not $i_Index Then ContinueLoop ; ignore 'Select Client Code' string (index 0) ; activate the firefox window and check for errors activating If Not WinActivate("SecureSync - Mozilla Firefox") Then _ ContinueLoop (MsgBox($MB_ICONERROR, 'Error', 'Unable to activate SecureSync window')) ; wait until the window is active and check for timeout If Not WinWaitActive("SecureSync - Mozilla Firefox", '', 5) Then _ ContinueLoop (MsgBox($MB_ICONERROR, 'Error', 'Timed out waiting for SecureSync window')) ; Selects the client Send("{SPACE}") Sleep(1500) Send("{DOWN " & $i_Index & "}") Sleep(1500) Send("{ENTER}") Sleep(1500) Send("{ENTER}") ExitLoop EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>SelectClientCode ClientCodes.txt mrmacro 1 Link to comment Share on other sites More sharing options...
kylomas Posted December 20, 2017 Share Posted December 20, 2017 Benners, When we get some clearer direction from the op we can present some reasonable alteratives....good idea externalizing the data... Perhaps the op has enough to go on now.. Kylomas mrmacro 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mrmacro Posted December 20, 2017 Author Share Posted December 20, 2017 thanks Kylomas the reply to your question Why do you do send('{down 1}')? As you worked out i am sending the keys to a website, also your explanation of a 1D array is a great help, i had sort of worked this out but confirmation from you helps my understanding even more your examples and the ones from benners have given the answer to the code that i couldnt quite get the syntax correct ( Using the client code and getting the index of it in the combo box) benners, thanks for the extra code using a text file , i would probably at some point have made it that if the codes change i wouldn't need to keep altering the main script and big big thanks to you both mrmacro Link to comment Share on other sites More sharing options...
kylomas Posted December 20, 2017 Share Posted December 20, 2017 Np...good luck....you know where we are... mrmacro 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
benners Posted December 20, 2017 Share Posted December 20, 2017 16 minutes ago, kylomas said: When we get some clearer direction from the op we can present some reasonable alteratives....good idea externalizing the data... Yep thought I'd offer a few alternatives. Googled SecureSync and tested as much of the sendkeys as possible. I assume when the user logs on it produces a screen that the keys navigate through. Hopefully the code will work and won't require Case statements Link to comment Share on other sites More sharing options...
mrmacro Posted December 20, 2017 Author Share Posted December 20, 2017 (edited) 13 minutes ago, benners said: Yep thought I'd offer a few alternatives. Googled SecureSync and tested as much of the sendkeys as possible. I assume when the user logs on it produces a screen that the keys navigate through. Hopefully the code will work and won't require Case statements yes exactly that ! when the user logs on it produces a screen that the keys navigate through. from our previous conversation in my other post i knew it was a long way of doing it using case statements , i do hope to eventually to have a gui at the start that prompts for username, password and the client code and then just navigates to where i need to be, currently it a separate script to do the login part and then this one to select the client code but i will have a go myself on this one again.i cant keep asking you all to do it, i will have nothing to stop the boredom of work. you have been a great help i knew what i wanted to do and that it could be achieved , but i just didnt quite have the right syntax to actually achieve it. big thumbs up to you all mrmacro Edited December 20, 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