Micro Focus QTP (UFT) Forums
QTP/UFT - Storing Multiple Arrays In An Array - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: QTP/UFT - Storing Multiple Arrays In An Array (/Thread-QTP-UFT-Storing-Multiple-Arrays-In-An-Array)



QTP/UFT - Storing Multiple Arrays In An Array - Eitel13 - 07-17-2018

Also posted on stackoverflow with same subject line.

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

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.