Forum Discussion
tristaanogre
14 years agoEsteemed Contributor
Try using aqFile methods.
First, use the OpenTextFile method to open the CSV file. This method will return an aqTextFile object which allows you to use WriteLine to the text file.
Now, as to the line you're going to write. A CSV file consists of rows of values separated by specific characters. This is a concept that TestComplete calls a string list. So, you would use aqString methods to work with a string list to create a row for that table and then use WriteLine to write that row out. You would use aqString.AddListItem to add items to the end of your string list from your array. Keep adding items to that list until you reach the end of your row and then pass the result of that to your writeline method to write the whole row to your text file.
So... you'd need a nested set of for-loops to loop through the two dimensions of your array. The outer loop would by your "row" which would include your WriteLine call. Before the writeline call, you'd have your inner loop which would go through your columns adding to your list item.
so, in Pseudo code, it would look something like this:
Note that the above code has not been tested but hopefully the concept comes out clear.
As for modifying an existing CSV file, you could use similar methodology in that you would use methods of the aqTextFile and aqString to read values, modify values, and write them back out.
First, use the OpenTextFile method to open the CSV file. This method will return an aqTextFile object which allows you to use WriteLine to the text file.
Now, as to the line you're going to write. A CSV file consists of rows of values separated by specific characters. This is a concept that TestComplete calls a string list. So, you would use aqString methods to work with a string list to create a row for that table and then use WriteLine to write that row out. You would use aqString.AddListItem to add items to the end of your string list from your array. Keep adding items to that list until you reach the end of your row and then pass the result of that to your writeline method to write the whole row to your text file.
So... you'd need a nested set of for-loops to loop through the two dimensions of your array. The outer loop would by your "row" which would include your WriteLine call. Before the writeline call, you'd have your inner loop which would go through your columns adding to your list item.
so, in Pseudo code, it would look something like this:
function blah(array)
{
var InnerIndex, OuterIndex;
var MyString;
var MyCSVFile = aqFile.OpenTextFile("C:\\Folder1\\MyCSVFile.CSV", faReadWrite, ctANSI, true)
for (OuterIndex=0;OuterIndex<=RowHighBound;OuterIndex++)
{
MyString = "";
for(InnerIndex=0;InnerIndex<=ColumnHighBound;InnerIndex++)
{
MyString = aqString.AddListItem(MyString, array[OuterIndex, InnerIndex], -1)
}
MyCSVFile.WriteLine(MyString)
}
}
Note that the above code has not been tested but hopefully the concept comes out clear.
As for modifying an existing CSV file, you could use similar methodology in that you would use methods of the aqTextFile and aqString to read values, modify values, and write them back out.
Related Content
- 3 years ago
- 6 years ago
- 12 years ago
- 5 years ago
Recent Discussions
- 2 days ago
- 7 days ago
- 11 days ago