TurboCoder
TurboCoder

Reputation: 1011

QTP/UFT - Storing Multiple Arrays In An Array

I have a function that imports a sheet to the global sheet and then loops through the columns and rows to create an array.

Code

Public Function importArray()

    DataTable.ImportSheet "location","Lists", "Global"

    rowCount = DataTable.GetSheet(dtGlobalSheet).GetRowCount -1
    columnCount = DataTable.GetSheet(dtGlobalSheet).GetParameterCount

    ReDim myArray(-1)  

    For x = 1 to columnCount Step 1

        For i = 0 to rowCount Step 1

            ReDim Preserve myArray(UBound(myArray) + 1)
            myArray(i) = Datatable.Value(x, dtGlobalSheet)      
            Datatable.SetNextRow

        Next

        MsgBox Join(myArray, vbNewLine)

    Next

End Function

So now that I know I can get the columns into an array, I need to store each array individually.

For example:

Main array = myArray(i)

Call importArray() to get array

Column count = 2

Column names = Name, Surname

Store array into array variable with name as column name

Populate myArray() with stored arrays

myArray(Name(), Surname())

The reason I want to do this is because I have a function that will need to reference these arrays to look for a value in the array then do some logic. While I know that I can just create arrays one by one, the problem is that I might have 20 arrays to use, in which case the code will become really bulky.

Perhaps there is a better way to do what I am thinking of doing, but otherwise, help on this would be really appreciated.

Upvotes: 0

Views: 1282

Answers (1)

Bela Tamas Jozsa
Bela Tamas Jozsa

Reputation: 714

Use multidimensional arrays

'Declare a Dynamic Array
Dim arrData()

' Make it a multidimensional array
ReDim Preserve arrData(rowCount, colCount)

For Loop row
    For Loop col
       arrData(row, col) = ...
    Next
Next

column names as array indexes is not okay - that is a dictionary (Map) already

Upvotes: 1

Related Questions