I'm in SAP, trying to dump an array of GuiLabel s into a jagged array.
First I parse the child's ID to get the row and column while filtering out non-GuiLabel objects.
This part works.
I created a variant array that represents the lines, in each line element I put an array of strings representing each 'label columns'.
This part seems to work with no errors
The problem occurs when I try to read back from this first variant array.
I followed this great thread -> How do I set up a "jagged array" in VBA?
and by the end of it, it seems I should be able to read each of my elements with a simple Debug.Print myRows(0)(0) , however I get a type mismatch !
Any advice appreciated !
Function LabelToArray(LblCollection As Variant) As Variant()
Dim myid As String
Dim mycolumn As String
Dim myrow As String
Dim intLastRow As Integer
Dim intLastCol As Integer
Dim myRows As Variant
Dim myColumns() As String
' Create first row
ReDim myRows(0)
' For every child object in the collection
For Each mychld In LblCollection
' Only execute for labels
If mychld.Type = "GuiLabel" Then
' Get column and row of current label
myid = Split(mychld.ID, "[")(4)
myid = Mid(myid, 1, Len(myid) - 1)
mycolumn = Split(myid, ",")(0)
myrow = Split(myid, ",")(1)
' New row ? Reset column counter, set row counter and redim the array of rows
' This will fail spectacularly if SAP stop giving rows in numerical order
If myrow > intLastRow Then intLastCol = 0: intLastRow = myrow: ReDim myRows(myrow)
' Reset or resize this line's columns array
If intLastCol = 0 Then
' Set filled out 'myColumns' array into correct 'myRows' object
If myrow <> 0 Then myRows(myrow - 1) = myColumns
' testing, print last column in this row
If myrow <> 0 Then Debug.Print myColumns(UBound(myColumns))
' testing, print first column in this row
If myrow <> 0 Then Debug.Print myColumns(0)
' testing, print number of columns
If myrow <> 0 Then Debug.Print UBound(myColumns)
' Reset myColumns array because we're on a new line
ReDim myColumns(0)
Else
ReDim Preserve myColumns(intLastCol)
End If
myColumns(intLastCol) = mychld.Text
intLastCol = intLastCol + 1
'Debug.Print mycolumn & "," & myrow
End If
Next
' Copy last row into array
myRows(myrow) = myColumns
' SEEMS TO WORK FINE UP TO THIS POINT !
Debug.Print UBound(myRows)
Debug.Print myRows(0)(0) 'THIS LINE FAILS, TYPE MISMATCH (run-time error 13) ! I also tried cstr(myRows(0)(0))
LabelToArray = myRows
End Function