szyMarek Posted October 21, 2022 Posted October 21, 2022 (edited) Hi. I'm stuck on a part of the code. Probably trivial and yet I'm stuck. In the array "$aListPlikow" I keep a list of files located in a given directory. In the array "$aListFileNames" I hold the abbreviated names of those files. Using the code below, I generate a window with buttons, the number of which depends on the number of values in the "$aListPlikow" array. expandcollapse popup#include <ComboConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <File.au3> #Include <Date.au3> #include <FontConstants.au3> #include <Array.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Excel.au3> #include <GUIConstantsEx.au3> #include <Date.au3> #Include <GuiButton.au3> Global $hButtons[10] Local $aListaPlikow[3] = ["2","AAAAAA_Temp1.xls","YYYYY_Temp2.xls"] Local $aListaPlikowNazwy[3] = ["2","Temp1","Temp2"] If $aListaPlikow[0] = 1 Then $hGUI = GUICreate("Wypelnij tresc pola 12", 1014, 400) Else $hGUI = GUICreate("WYBÓR TEMPLATE", 400, 80+90*$aListaPlikow[0]) $i = 0 While $i < $aListaPlikow[0] $hButtons[$i] = GUICtrlCreateButton($aListaPlikowNazwy[$i+1],20,120+($i*60),360,50) $i = $i+1 WEnd GUISetState() EndIf Local $iMsg, $iButton While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $hButtons[0] To $hButtons[$aListaPlikow[0]] $iButton = $iMsg - $hButtons[0] ConsoleWrite("button " & $iButton & " was pushed" & @CRLF) EndSwitch WEnd How can I tell which button has been pressed? Each of them is supposed to trigger a different action. Edited October 21, 2022 by szyMarek
Solution Nine Posted October 21, 2022 Solution Posted October 21, 2022 Something like this (untested) : Local $iMsg, $iButton While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $aButtons[0] To $aButtons[UBound($aButtons) - 1] $iButton = $iMsg - $aButtons[0] ConsoleWrite("button " & $iButton & " was pushed" & @CRLF) EndSwitch WEnd Next time, provide a runable script so we do not have to start from scratch writing our suggestions... abberration 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
szyMarek Posted October 21, 2022 Author Posted October 21, 2022 26 minutes ago, Nine said: Something like this (untested) : Local $iMsg, $iButton While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $aButtons[0] To $aButtons[UBound($aButtons) - 1] $iButton = $iMsg - $aButtons[0] ConsoleWrite("button " & $iButton & " was pushed" & @CRLF) EndSwitch WEnd Next time, provide a runable script so we do not have to start from scratch writing our suggestions... Nope 😕
Nine Posted October 21, 2022 Posted October 21, 2022 3 minutes ago, szyMarek said: Nope Really ? You will not make the effort to provide something for us, but you still ask for help ? That is not very polite... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
szyMarek Posted October 21, 2022 Author Posted October 21, 2022 1 minute ago, Nine said: Really ? You will not make the effort to provide something for us, but you still ask for help ? That is not very polite... I'm sorry. Actually I should have mentioned that I've updated the code and you can run it now, so you can copy it and test it. Unfortunately, the solution you proposed doesn't work and I can't get it to work. Again, I apologize for being rude.
AutoBert Posted October 21, 2022 Posted October 21, 2022 Try it this way: expandcollapse popup#include <ComboConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <File.au3> #Include <Date.au3> #include <FontConstants.au3> #include <Array.au3> #include <String.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Excel.au3> #include <GUIConstantsEx.au3> #include <Date.au3> #Include <GuiButton.au3> Global $hButtons[10] Global $aListaPlikow[3] = ["2","AAAAAA_Temp1.xls","YYYYY_Temp2.xls"] Global $aListaPlikowNazwy[3] = ["2","Temp1","Temp2"] If $aListaPlikow[0] = 1 Then $hGUI = GUICreate("Wypelnij tresc pola 12", 1014, 400) Else $hGUI = GUICreate("WYBÓR TEMPLATE", 400, 80+90*$aListaPlikow[0]) $i = 1 While $i < $aListaPlikow[0] +1 $hButtons[$i] = GUICtrlCreateButton($aListaPlikowNazwy[$i],20,60+($i*60),360,50) $hButtons[0] = $i ;$hButtons[0] remembers last Index with ButtonId $i = $i+1 WEnd GUISetState() EndIf Global $iMsg, $iButton While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $hButtons[1] To $hButtons[$hButtons[0]] ConsoleWrite(GUICtrlRead($iMsg) & " was pushed" & @CRLF) ConsoleWrite('The Button ID = ' & $iMsg & @CRLF) ConsoleWrite('Associated File = ' & $aListaPlikow[$iMsg - $hButtons[0]] & @CRLF) EndSwitch WEnd mfg (auto)Bert szyMarek 1
szyMarek Posted October 21, 2022 Author Posted October 21, 2022 23 minutes ago, AutoBert said: Try it this way: mfg (auto)Bert I'ts working. THX
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