Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to convert a single dimension array to two dimensional array
#1
Solved: 9 Years, 5 Months, 3 Weeks ago
hello guys,

I am transfering csv data into array..
I am getting single dimensional array..
but my requirement is to store csv data into two dimensional array..

so how how can i convert single dimensional array into two dimensional array in qtp//
can anyone helpout this,
Reply
#2
Solved: 9 Years, 5 Months, 3 Weeks ago
You have not mentioned proper data information with your question. But what I got to know from your question I am sending possible solution:

First import that data from CSV to data table by this below formula:
DataTable.ImportSheet(FileName, SRCSheetName, DestinationSheetName)

After doing this, You will have all the csv data into your specified data table sheet.

Now if your data is in two columns, take the count of data from data table and based on the row count, create a for loop till the last count and insert the data in two dimension array like below:

Code:
Dim a()

rcount = DataTable.GetRowCount

ReDim a(rcount-1, 1)

For i = 0 To rcount
    For j = 0 To 1 Step 1
        a(i, j) = DataTable.Value(...PrameterID..)
    Next
Next

Use this code and let me know if still there is any problem.
Reply
#3
Solved: 9 Years, 5 Months, 3 Weeks ago
But pranikgarg
my requirement is csv data should not be loaded into datatable or excel...wat eve the file it is loading into single array but the data should be stored into two dimensional array...without loading into data table and excel...the single dimensional array should be converted into two dimensional..
Reply
#4
Solved: 9 Years, 5 Months, 3 Weeks ago
In this case you can use that single dimensional array to create double dimensional array.

Get the count of that array and loop through the same array and assign same values to two dimensional array:

Code:
Dim TwoDimArray()

singleDimArray = Array("a", "b", "c", "d", "e", "f", "g")

ReDim TwoDimArray(UBound(singleDimArray), 1)

For i = 0 To UBound(singleDimArray) Step 2
    For j = 0 To 1 Step 1
        If j = 0 Then
            TwoDimArray(i, j) = singleDimArray(i)
            Else If i<6 Then
                TwoDimArray(i, j) = singleDimArray(i+1)
            End IF            
        End If
    Next
Next

After running this code remove empty element from the array. This code will traverse your single dimensional array and insert each value from the single dimensional array to two dimensional array.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  String Array Declaration Bhuvana 0 1,008 01-07-2020, 12:59 PM
Last Post: Bhuvana
  How To Capture Array Value into Excel Worksheet? Studymode 0 1,418 01-09-2018, 08:37 AM
Last Post: Studymode
  Choosing element from array marvson 1 1,900 06-29-2016, 02:55 PM
Last Post: Ankesh
  [UFT] Get Item of ListBox and convert it to array felino 1 2,434 11-26-2015, 02:20 PM
Last Post: felino
  Need a logic in array - QTP surestud 4 3,187 08-20-2015, 02:47 PM
Last Post: cuongtv

Forum Jump:


Users browsing this thread: 1 Guest(s)