Page 1 of 1

Accessing Excel Data in VB.net

Posted: Wed Dec 03, 2014 6:07 pm
by verm
I created two data connectors, one for each Excel file that I have. Each file has one column of data, I just need to read the data in a couple of loops. I tried viewing the tutorials on data connectors, but I do not understand how to access this data from within my VB.net user code module. What is the best way to go about this?

Re: Accessing Excel Data in VB.net

Posted: Thu Dec 04, 2014 4:54 pm
by Support Team
Hi verm,

In order to access your data you need to create Module variables (as described here) and bind these variables to your data connector (as described here).
It is also possible to use variables in code modules. Please find a detailed description about that in this section

Regards,
Markus (S)

Re: Accessing Excel Data in VB.net

Posted: Thu Dec 04, 2014 8:05 pm
by verm
Is there a way I could instead just read row by row directly from the file when I need to? I still don't quite understand how to use the data connectors so would it be easier to do it strictly through user code? The main reason I am asking this is that I want to be able to loop through each row of the one file andbased on what is in each cell, different actions will be executed.

Re: Accessing Excel Data in VB.net

Posted: Thu Dec 04, 2014 8:11 pm
by krstcs
Honestly, using the method outlined by Markus is the easiest thing to do. Doing it in code is a pain and it won't propagate into other test modules without using global or test-case parameters, which is way more work than you should be doing.

Read up on the data connectors and data-driven testing and try it with a simple test.

In my opinion, if someone can't do it with data connectors, then there's very little chance they would be able to do it with user-code. User-code is for developers. If you are a developer then you already know that it is hard to manage all of that, and Ranorex already did all the work for you, if you set up your tests correctly.

I'm a C# developer who happens to do Ranorex and I MUCH prefer to use their data connectors so I don't have to fool with the overhead and code.

Re: Accessing Excel Data in VB.net

Posted: Thu Dec 04, 2014 10:28 pm
by verm
I still don't understand how to load my connector and then access a given row from the data in my user code. Do I use something like

Code: Select all

Ranorex.Core.Data.ExcelDataConnector
?

Re: Accessing Excel Data in VB.net

Posted: Thu Dec 04, 2014 10:38 pm
by krstcs
OK, I don't think we are on the same page.

The data connector is setup so that it loops through each row in the data set and runs each test module in that test case for the data in the row.

If you have this structure:

Code: Select all

TestSuite
    TestCase1 ==> SpreadSheet.xls  (the data connector) (4 rows of data, in 1 column)
        Recording1 --> bind var1 to column1 (or whatever)
Recording 1 will be run once for EACH ROW (so 4 total runs) in the spreadsheet. The connector will pass in the rows in order starting with row 2 (1 is the titles of the columns) and will pass column1 into var1 in Recording1, if you have it bound.

You pass a specific row by using the filter at the bottom of the data source window. So if you wanted TestCase1 to only run for row 1, you would set the filter to "1" (sans quotes).

If you read the user guide it will tell you everything you need to know to get it working.