232showtime Posted August 29, 2016 Posted August 29, 2016 (edited) Hi good day, please I need help with counting array rows, Im getting 0 value, but if I use ArrayExtract I can count the exact array row count. my question is why I cant get the array row count using $aResult? HotKeySet("{F2}", "Test") HotKeySet("{F3}", "CountRow") Global $aResult;, $aExtract While 1 Sleep(100) WEnd Func Test() ; Create application object and open an example workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\testing.xlsx") If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & @DesktopDir & "\testing.xlsx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf Local $aResult = _Excel_RangeRead($oWorkbook, 1, "a1:e40", 2) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 2", "Data successfully read." & @CRLF & "Please click 'OK' to display the formulas of cells A1:C5 of sheet 1.") ;$aExtract = _ArrayExtract($aResult, 0, -1, 4, 4) $aDsply = _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeRead Example 2 - Cells A1:e40 of sheet 1") EndFunc ;==>Test Func CountRow() $RowCount = UBound($aResult, $UBOUND_ROWS) MsgBox(64, "Success", "Row Count: " & $RowCount) EndFunc ;==>CountRow are there any other solution rather than _ArrayExtract??? Edited August 29, 2016 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
mikell Posted August 29, 2016 Posted August 29, 2016 Please try to remove the "Local" before $aResult in the func test() 232showtime 1
232showtime Posted August 29, 2016 Author Posted August 29, 2016 (edited) wth? its kinda weird... any explanation about this please???? Edited August 29, 2016 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
mikell Posted August 29, 2016 Posted August 29, 2016 As you redeclare $aResult in the func, you create a new var which will work only inside the func, reason why _ArrayExtract worked ... inside the func CountRow() used the $aResult declared as Global at the top of the script, and this one remained empty. You might check this using _ArrayDisplay or so 232showtime 1
232showtime Posted August 29, 2016 Author Posted August 29, 2016 very nice, got it thanks... ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
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