Siwa Posted September 15, 2020 Share Posted September 15, 2020 I want to create a GUI which uses a FOR/NEXT loop depending on names of some people saved in an excel file. The GUI repeats by the number of people which is in the excel file. Some part of the code : Global $Names = _Excel_RangeRead($oWorkbook, 2, "B2:C"&Ubound($Total_Rows), 2) $hGUI = GUICreate("My GUI list",700,500) _GUIScrollbars_Generate($hGUI, 500, 100+(UBound($Names, 1)*110)+50) For $iIndex = 0 to UBound($Names, 1) - 1 $sData = $iIndex & "|" & $Names[$iIndex][1] & "|" & $Names[$iIndex][0] $GroupName = GUICtrlCreateGroup($Names[$iIndex][0] &" "& $Names[$iIndex][1], 70, 100+$iIndex*110, 600, 100,-1,0x400000) Global $idDate = GUICtrlCreateDate("2020/1/1", 550, 150+$iIndex*110, 100, 20) Next ( _GUIScrollbars_Generate is used from this topic, to enable scroll for the GUI ) My problem now is I want to set a variable for the GUICtrlCreateDate to get the date later and save it in some log file, depending on the people's number.(and change a depended calendar view set to red on specific dates provided by the person operating on my GUI.) Thanks for your help an advance. Link to comment Share on other sites More sharing options...
Subz Posted September 15, 2020 Share Posted September 15, 2020 You can create an array to hold the control information and then reference it later, example (untested). Global $Names = _Excel_RangeRead($oWorkbook, 2, "B2:C"&Ubound($Total_Rows), 2) Global $aGroupNames[UBound($Names) + 1][3] $hGUI = GUICreate("My GUI list",700,500) _GUIScrollbars_Generate($hGUI, 500, 100+(UBound($Names, 1)*110)+50) For $iIndex = 0 to UBound($Names, 1) - 1 $aGroupNames[$iIndex][0] = $iIndex & "|" & $Names[$iIndex][1] & "|" & $Names[$iIndex][0] $aGroupNames[$iIndex][1] = GUICtrlCreateGroup($Names[$iIndex][0] &" "& $Names[$iIndex][1], 70, 100+$iIndex*110, 600, 100,-1,0x400000) $aGroupNames[$iIndex][2] = GUICtrlCreateDate("2020/1/1", 550, 150+$iIndex*110, 100, 20) Next Siwa 1 Link to comment Share on other sites More sharing options...
Siwa Posted September 15, 2020 Author Share Posted September 15, 2020 (edited) 1 hour ago, Subz said: You can create an array to hold the control information and then reference it later, example (untested). Global $Names = _Excel_RangeRead($oWorkbook, 2, "B2:C"&Ubound($Total_Rows), 2) Global $aGroupNames[UBound($Names) + 1][3] $hGUI = GUICreate("My GUI list",700,500) _GUIScrollbars_Generate($hGUI, 500, 100+(UBound($Names, 1)*110)+50) For $iIndex = 0 to UBound($Names, 1) - 1 $aGroupNames[$iIndex][0] = $iIndex & "|" & $Names[$iIndex][1] & "|" & $Names[$iIndex][0] $aGroupNames[$iIndex][1] = GUICtrlCreateGroup($Names[$iIndex][0] &" "& $Names[$iIndex][1], 70, 100+$iIndex*110, 600, 100,-1,0x400000) $aGroupNames[$iIndex][2] = GUICtrlCreateDate("2020/1/1", 550, 150+$iIndex*110, 100, 20) Next Thanks for your help. But this arrays giving me errors about syntax error. How can I declare it ? Edited September 15, 2020 by Siwa Link to comment Share on other sites More sharing options...
Subz Posted September 15, 2020 Share Posted September 15, 2020 Can you post the full script + provide an example Excel workbook? Siwa 1 Link to comment Share on other sites More sharing options...
Siwa Posted September 16, 2020 Author Share Posted September 16, 2020 (edited) 20 hours ago, Subz said: Can you post the full script + provide an example Excel workbook? really sorry for the delay. Here is the code, and the file. expandcollapse popup#NoTrayIcon #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include "GUIScrollbars_Ex.au3" #include <FTPEx.au3> #include <GuiButton.au3> Global $idDate Global $iIndex GLobal $aGroupNames Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, "C:\1\99.xlsx",False,True) Global $aWorkSheets = _Excel_SheetList($oWorkbook) $oWorkbook.Sheets(2).Activate Global $Total_Rows = _Excel_RangeRead($oWorkbook, Default , $oWorkbook.ActiveSheet.Usedrange.Columns("C:C"),1) Global $Total_Rows_Count = Ubound($Total_Rows) Global $Names = _Excel_RangeRead($oWorkbook, 2, "B2:C"&Ubound($Total_Rows), 2) CreateGUI() Func CreateGUI() $hGUI = GUICreate("My GUI list",700,500) ; will create a dialog box that when displayed is centered - UBound($Names, 1) - 1 _GUIScrollbars_Generate($hGUI, 500, 100+(UBound($Names, 1)*110)+50) For $iIndex = 0 to UBound($Names, 1) - 1 $sData = $iIndex & "|" & $Names[$iIndex][1] & "|" & $Names[$iIndex][0] $GroupName = GUICtrlCreateGroup($Names[$iIndex][0] &" "& $Names[$iIndex][1], 70, 100+$iIndex*110, 600, 100,-1,0x400000) $aGroupNames[$iIndex][0] = GUICtrlCreateDate("2020/10/25", 550, 150+$iIndex*110, 100, 20) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_RESTORE _GUIScrollbars_Restore($hGUI) Case $GUI_EVENT_MINIMIZE _GUIScrollbars_Minimize($hGUI) EndSwitch WEnd if Not $idDate = "2020/10/25" Then MsgBox($MB_SYSTEMMODAL, "Date", GUICtrlRead($idDate)) EndIf GUIDelete($hGUI) EndFunc ;_GetDateOnline() Func _GetDateOnline() Local $sServer = 'ftpupload.net' Local $sUsername = 'gigfa_26732342' Local $sPass = '225364' Local $sPath ='/htdocs/date.txt' Local $hFile, $sText Local $hOpen = _FTP_Open('MyFTP Control') Local $hConn = _FTP_Connect($hOpen, $sServer, $sUsername, $sPass) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else $hFile=_FTP_FileOpen($hConn,$sPath) Global $Today_Date=BinaryToString(_FTP_FileRead($hFile,9999)) ;aus Datei lesen und in Format wandeln _FTP_FileClose($hFile) MsgBox($MB_APPLMODAL, 'README: ',$Today_Date) EndIf _FTP_Close($hConn) _FTP_Close($hOpen) EndFunc Edited September 16, 2020 by Siwa Link to comment Share on other sites More sharing options...
Siwa Posted September 16, 2020 Author Share Posted September 16, 2020 test.rar Link to comment Share on other sites More sharing options...
Subz Posted September 16, 2020 Share Posted September 16, 2020 As I wrote above you needed to declare the array after the range read, here is an example: Note I used random day, just so you can see the result, just close the tool and you should see message box for dates that don't equal the $idDate (converted to long date format). expandcollapse popup#NoTrayIcon #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include "GUIScrollbars_Ex.au3" #include <FTPEx.au3> #include <GuiButton.au3> Global $idDate = "2020/10/25" Global $iIndex Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Test_1.xlsx",False,True) Global $aWorkSheets = _Excel_SheetList($oWorkbook) $oWorkbook.Sheets(2).Activate Global $Total_Rows = _Excel_RangeRead($oWorkbook, Default , $oWorkbook.ActiveSheet.Usedrange.Columns("C:C"),1) Global $Total_Rows_Count = Ubound($Total_Rows) Global $Names = _Excel_RangeRead($oWorkbook, 2, "B2:C"&Ubound($Total_Rows), 2) Global $aGroupNames[UBound($Names)][3] ;~ Declare the group name array, same number of rows as the spreadsheet CreateGUI() Func CreateGUI() Local $hGUI = GUICreate("My GUI list",700,500) ; will create a dialog box that when displayed is centered - UBound($Names, 1) - 1 _GUIScrollbars_Generate($hGUI, 500, 100+(UBound($Names, 1)*110)+50) For $iIndex = 0 to UBound($Names, 1) - 1 $aGroupNames[$iIndex][0] = $iIndex & "|" & $Names[$iIndex][1] & "|" & $Names[$iIndex][0] $aGroupNames[$iIndex][1] = GUICtrlCreateGroup($Names[$iIndex][0] &" "& $Names[$iIndex][1], 70, 100+$iIndex*110, 600, 100,-1,0x400000) $aGroupNames[$iIndex][2] = GUICtrlCreateDate("2020/10/" & Random(23, 26), 550, 150+$iIndex*110, 100, 20) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_RESTORE _GUIScrollbars_Restore($hGUI) Case $GUI_EVENT_MINIMIZE _GUIScrollbars_Minimize($hGUI) EndSwitch WEnd Local $idLongDate = _DateTimeFormat($idDate, 1) For $i = 0 To UBound($aGroupNames) - 1 If $idLongDate <> GUICtrlRead($aGroupNames[$i][2]) Then MsgBox(4096, "Info", "Group Name = " & GUICtrlRead($aGroupNames[$i][1]) & @CRLF & "Date = " & GUICtrlRead($aGroupNames[$i][2])) Next EndFunc Siwa 1 Link to comment Share on other sites More sharing options...
Siwa Posted September 16, 2020 Author Share Posted September 16, 2020 (edited) 28 minutes ago, Subz said: As I wrote above you needed to declare the array after the range read, here is an example: Note I used random day, just so you can see the result, just close the tool and you should see message box for dates that don't equal the $idDate (converted to long date format). expandcollapse popup#NoTrayIcon #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include "GUIScrollbars_Ex.au3" #include <FTPEx.au3> #include <GuiButton.au3> Global $idDate = "2020/10/25" Global $iIndex Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Test_1.xlsx",False,True) Global $aWorkSheets = _Excel_SheetList($oWorkbook) $oWorkbook.Sheets(2).Activate Global $Total_Rows = _Excel_RangeRead($oWorkbook, Default , $oWorkbook.ActiveSheet.Usedrange.Columns("C:C"),1) Global $Total_Rows_Count = Ubound($Total_Rows) Global $Names = _Excel_RangeRead($oWorkbook, 2, "B2:C"&Ubound($Total_Rows), 2) Global $aGroupNames[UBound($Names)][3] ;~ Declare the group name array, same number of rows as the spreadsheet CreateGUI() Func CreateGUI() Local $hGUI = GUICreate("My GUI list",700,500) ; will create a dialog box that when displayed is centered - UBound($Names, 1) - 1 _GUIScrollbars_Generate($hGUI, 500, 100+(UBound($Names, 1)*110)+50) For $iIndex = 0 to UBound($Names, 1) - 1 $aGroupNames[$iIndex][0] = $iIndex & "|" & $Names[$iIndex][1] & "|" & $Names[$iIndex][0] $aGroupNames[$iIndex][1] = GUICtrlCreateGroup($Names[$iIndex][0] &" "& $Names[$iIndex][1], 70, 100+$iIndex*110, 600, 100,-1,0x400000) $aGroupNames[$iIndex][2] = GUICtrlCreateDate("2020/10/" & Random(23, 26), 550, 150+$iIndex*110, 100, 20) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_RESTORE _GUIScrollbars_Restore($hGUI) Case $GUI_EVENT_MINIMIZE _GUIScrollbars_Minimize($hGUI) EndSwitch WEnd Local $idLongDate = _DateTimeFormat($idDate, 1) For $i = 0 To UBound($aGroupNames) - 1 If $idLongDate <> GUICtrlRead($aGroupNames[$i][2]) Then MsgBox(4096, "Info", "Group Name = " & GUICtrlRead($aGroupNames[$i][1]) & @CRLF & "Date = " & GUICtrlRead($aGroupNames[$i][2])) Next EndFunc Thanks for your great help. Btw, I did it the hard way be declaring the array : GLobal $aGroupNames[$Total_Rows_Count][$Total_Rows_Count] And it was not eye candy. But yours is way better. 🙏 Edited September 16, 2020 by Siwa Link to comment Share on other sites More sharing options...
Siwa Posted September 18, 2020 Author Share Posted September 18, 2020 Thanks for your time @Subz I came across another issue. How can I define an event for my buttons ? The while loop does not recognize my variable variable. While 1 Switch GUIGetMsg() Case $aGroupNames[$iIndex][4] MsgBox(0,"clicked","") EndSwitch WEnd Link to comment Share on other sites More sharing options...
Subz Posted September 18, 2020 Share Posted September 18, 2020 When it comes to large amount of control ids within an array I try to group the controls, i.e. 200, 201, 202 etc... then you can just use Case Array[0] To Array[LastRow], example: For $iIndex = 0 to UBound($Names, 1) - 1 $aGroupNames[$iIndex][0] = $iIndex & "|" & $Names[$iIndex][1] & "|" & $Names[$iIndex][0] $aGroupNames[$iIndex][1] = GUICtrlCreateGroup($Names[$iIndex][0] &" "& $Names[$iIndex][1], 70, 100+$iIndex*110, 600, 100,-1,0x400000) $aGroupNames[$iIndex][2] = GUICtrlCreateDate("2020/10/" & Random(23, 26), 550, 150+$iIndex*110, 100, 20) Next For $iIndex = 0 To UBound($Names) - 1 $aGroupNames[$iIndex][3] = GUICtrlCreateButton("Button " & $iIndex, 550, 130+$iIndex*110, 100, 20) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_RESTORE _GUIScrollbars_Restore($hGUI) Case $GUI_EVENT_MINIMIZE _GUIScrollbars_Minimize($hGUI) Case $aGroupNames[0][3] To $aGroupNames[UBound($aGroupNames) - 1][3] MsgBox(4096, "", GUICtrlRead($nMsg)) EndSwitch WEnd Siwa 1 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