Jump to content

need help Array Count rows


Recommended Posts

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 by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...