JoeBar Posted November 24, 2019 Share Posted November 24, 2019 (edited) Hi, i started a dynamically GUI generation with Assign to create TabItems and populate them with some controls (buttons, text, image...). All is generated through a loop like this : For $i = 0 To UBound($aCSV) - 1 Step 4 Assign("idtab" & $i, GUICtrlCreateTabItem($aCSV[$i])) GUISwitch($DltGui, Eval("idtab" & $i)) GUICtrlCreateLabel($aCSV[$i], 170, 95, 393, 44, $SS_CENTER, -1) GUICtrlSetFont(-1, 28, 400, 0, "Segoe UI Symbol") GUICtrlSetColor(-1, "0x000080")) Assign("btnopen" & $i, GUICtrlCreateButton("Open the file", 445, 231, 133, 37, -1, -1)) GUICtrlSetFont(-1, 12, 400, 0, "MS Reference Sans Serif") GUICtrlSetTip(-1, "Open the DLed file") GUICtrlSetOnEvent(-1, _Launch) GUICtrlSetState(-1, $GUI_DISABLE) So logically, the button IDs "Open the file" are being stored in "btnopen0", "btnopen4", "btnopen8", etc... All is working great, but further in a func, i try to enable the "btnopen" & $i with the following command : GUICtrlSetState(Eval("btnopen" & GUICtrlRead($tab) * 4), $GUI_ENABLE) I'm trying to retrieve the button ID associated with the current TabItem, to enable it, but i don't manage to. Have you got an idea ? Edited November 24, 2019 by JoeBar Link to comment Share on other sites More sharing options...
seadoggie01 Posted November 24, 2019 Share Posted November 24, 2019 Try writing "btnopen" & GUICtrlRead($tab) * 4 to the console to see what you variable you are reading. Also, posting a reproduce-able script is helpful since we don't know what $tab is or how it's assigned All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
JoeBar Posted November 24, 2019 Author Share Posted November 24, 2019 (edited) Nothing is displayed in the console, that's why i'm asking if i'm correct with the good value. $tab is the handle of the Tab, "idtab" & $i represents the TabItems IDs as you can see. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiListBox.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <File.au3> #include <String.au3> Opt("GUIOnEventMode", 1) Global $DltGui = GUICreate("DltGui",600,315,-1,-1,-1,-1) Global $tab = GUICtrlCreatetab(20,85,560,200,-1,-1) GuiCtrlSetState(-1,2048) GUICtrlCreateTabItem("") _GUICtrlTab_SetCurFocus($tab,-1) Global $hConnection = GUICtrlCreateButton("Connection",20,20,135,50,-1,-1) GUICtrlSetOnEvent(-1,"_Retrieve") GUICtrlSetFont(-1,15,400,0,"MS Reference Sans Serif") GUICtrlSetTip(-1,"Retrieve games list") Global $sconnected = GUICtrlCreateLabel("Not connected",170,40,98,15,-1,-1) GUICtrlSetFont(-1,10,400,0,"MS Reference Sans Serif") GUICtrlSetColor(-1,"0xFF0000") GUICtrlSetBkColor(-1,"-2") GUICtrlSetTip(-1,"Statut") Global $Quit = GUICtrlCreateButton("Quit",445,20,133,50,-1,-1) GUICtrlSetOnEvent(-1,"_Exit") GUICtrlSetFont(-1,15,400,0,"MS Reference Sans Serif") GUICtrlSetTip(-1,"Quit") Global $hprogress = GUICtrlCreateProgress(380,289,198,20,-1,-1) GUICtrlSetTip(-1,"DL progress") Global $LabelPourcent = GUICtrlCreateLabel("",462,291,50,15,-1,-1) GUICtrlSetBkColor(-1,"-2") _GUICtrlTab_SetCurFocus($tab,0) That's for the static GUI part : a window with some buttons and a Tab. Now the GUI generation : expandcollapse popupFunc _Retrieve() Local $dData = InetRead("https:myserver.com/games.csv", 2) If $dData = "" Then MsgBox(16, "Error", "Access problem") Else GUICtrlSetData($sconnected, "Connected") GUICtrlSetColor($sconnected, $COLOR_GREEN) GUICtrlSetState($hConnexion, $GUI_DISABLE) Local $sData = BinaryToString($dData) Global $aCSV = StringRegExp($sData, ";*\s*([\w :\/\.'!-]+)", 3) ;~ _ArrayDisplay($aCSV, "Capture CSV") For $i = 0 To UBound($aCSV) - 1 Step 4 Assign("idtab" & $i, GUICtrlCreateTabItem($aCSV[$i])) GUISwitch($DltGui, Eval("idtab" & $i)) GUICtrlCreateLabel($aCSV[$i], 170, 95, 393, 44, $SS_CENTER, -1) GUICtrlSetFont(-1, 28, 400, 0, "Segoe UI Symbol") GUICtrlSetColor(-1, "0x000080") Assign("btndl" & $i, GUICtrlCreateButton("DL", 445, 166, 133, 37, -1, -1)) GUICtrlSetFont(-1, 14, 400, 0, "MS Reference Sans Serif") GUICtrlSetTip(-1, "DL the game") GUICtrlSetOnEvent(-1, _DL) Assign("btnopen" & $i, GUICtrlCreateButton("Open file", 445, 231, 133, 37, -1, -1)) ;~ ConsoleWrite(Eval("btnopen" & $i) & @CRLF) GUICtrlSetFont(-1, 12, 400, 0, "MS Reference Sans Serif") GUICtrlSetTip(-1, "Open the DLed game") GUICtrlSetOnEvent(-1, _Launch) GUICtrlSetState(-1, $GUI_DISABLE) Next For $i = 3 To UBound($aCSV) - 1 Step 4 GUISwitch($DltGui, Eval("idtab" & $i - 3)) Assign("description" & $i, GUICtrlCreateLabel($aCSV[$i - 1], 170, 145, 271, 123, $SS_CENTER, -1)) GUICtrlSetFont(-1, 18, 400, 0, "Segoe UI Symbol") GUICtrlSetColor(-1, "0x800000") Next GUICtrlSetState(Eval("idtab0"), $GUI_SHOW) EndIf EndFunc ;==>_Retrieve Func _DL() ;~ Local $snamefiledl = _ArrayToString(StringRegExp($aCSV[GUICtrlRead($tab) * 4 + 3], "\/([\w\-\.]+)$", 1)) ;~ Local $sSaveFile = FileSaveDialog("Save file", @DesktopDir, "Tous (*.*)", 16, $snamefiledl) ;~ If @error Then Return ;~ Local $urlfilauth = _StringInsert($aCSV[GUICtrlRead($tab) * 4 + 3], "login:password@", 8) ;~ Local $hInetget = InetGet($urlfilauth, $sSaveFile, 1, 1) ;~ ;~ Local $size = InetGetSize($urlfilauth) ;~ Local $nowRead = 0 ;~ Local $pourcent = 0 ;~ GUICtrlSetData($LabelSize,$size) ;~ Do ;~ Sleep(50) ;~ $nowRead = InetGetInfo($hInetget, 0) ;~ $pourcent = Int(($nowRead/$size)*100) ;~ GUICtrlSetData($hprogress,$pourcent) ;~ GUICtrlSetData($LabelPourcent,$pourcent&"%") ;~ Until InetGetInfo($hInetget, 2) ; Check if the download is complete. ;~ InetClose($hInetget) ;~ ConsoleWrite(GUICtrlRead($tab) * 4 & @CRLF) GUICtrlSetState(Eval("btnopen" & GUICtrlRead($tab) * 4), $GUI_ENABLE) EndFunc ;==>_DL All is working flawlessly, except the last line : GUICtrlSetState(Eval("btnopen" & GUICtrlRead($tab) * 4), $GUI_ENABLE) I'm just trying to enable the formerly disabled button and i don't manage to find the correct button ID of "Open File" on the current selected TabItem ... Edited November 24, 2019 by JoeBar Changed variable names for english understanding Link to comment Share on other sites More sharing options...
Developers Jos Posted November 24, 2019 Developers Share Posted November 24, 2019 @JoeBar, why is there a url to a game thing in your script? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JoeBar Posted November 24, 2019 Author Share Posted November 24, 2019 (edited) It's just a tool to DL files from our server to friends, it's for sharing some files (other programs, games, our selfmade musics, etc..) without getting them by a browser or FTP. It's just to have a nice GUI to do it. the csv is named games as we began with this, it's not related with game automation or whatever... Thanks for your help. Edited November 24, 2019 by JoeBar Link to comment Share on other sites More sharing options...
Developers Jos Posted November 24, 2019 Developers Share Posted November 24, 2019 (edited) Ok.. we will keep this thread open. 🙂 Edited November 24, 2019 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JoeBar Posted November 24, 2019 Author Share Posted November 24, 2019 7 minutes ago, Jos said: Ok.. we will keep this thread open. 🙂 Thanks, so do you know how to get the correct Button ID ? I'm lost on how to get it, and it's the only thing i need to have a functionnal app. Link to comment Share on other sites More sharing options...
seadoggie01 Posted November 24, 2019 Share Posted November 24, 2019 I would suggest using an array for holding your variables at least for next time... they're much easier to debug Is it possible that it's off by one tab? You create a blank tab at the beginning so the button would be switched on the tab after the one you click. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
JoeBar Posted November 24, 2019 Author Share Posted November 24, 2019 I know for Arrays, i will do with them next time. When i click on the button "DL", i check every time all the tabs, and no "Open" buttons are enabled. I see what you say, but for example GUISwitch($DltGui, Eval("idtab" & $i)) is poiting to the good TabItem each iteration. Am i obligated to Guiswitch for my GUICtrlSetState to work ? Link to comment Share on other sites More sharing options...
JoeBar Posted November 24, 2019 Author Share Posted November 24, 2019 Ok, i just found the guilty, when assigning, you must pass the flag 2 to declare Globally. So just Assign("btnopen" & $i, GUICtrlCreateButton("Open file", 445, 231, 133, 37, -1, -1), 2) is working. I'm curious at nobody pointed this rapidely, this could be solved just after my 1st post 😊 Thanks for everybody's help anyway Link to comment Share on other sites More sharing options...
seadoggie01 Posted November 24, 2019 Share Posted November 24, 2019 2 minutes ago, JoeBar said: I'm curious at nobody pointed this rapidely I can't say that I ever use Assign and Eval... there's really not a great reason to use them that I've seen. I thought that they were declared globally by default. Nice job finding it All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
JoeBar Posted November 25, 2019 Author Share Posted November 25, 2019 10 hours ago, seadoggie01 said: I can't say that I ever use Assign and Eval... there's really not a great reason to use them that I've seen. I thought that they were declared globally by default. Nice job finding it I was looking for a way to dynamically assign vars in a loop, and i've found 2 ways : Assign & Array. As i knew Arrays, i gave a try to Assign. The main reason it's not used as many of the Arrays is, i think, the syntax which is heavy (excuse my english i'm french) and not user friendly. Thank you 🤓. Link to comment Share on other sites More sharing options...
jchd Posted November 25, 2019 Share Posted November 25, 2019 Yep, that and it's bad style in 99.999% of contexts. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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