Accessing Excel Data in VB.net

Class library usage, coding and language questions.
verm
Posts: 4
Joined: Mon Dec 01, 2014 5:04 pm

Accessing Excel Data in VB.net

Post by verm » Wed Dec 03, 2014 6:07 pm

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Accessing Excel Data in VB.net

Post by Support Team » Thu Dec 04, 2014 4:54 pm

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)
.
Image

verm
Posts: 4
Joined: Mon Dec 01, 2014 5:04 pm

Re: Accessing Excel Data in VB.net

Post by verm » Thu Dec 04, 2014 8:05 pm

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.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Accessing Excel Data in VB.net

Post by krstcs » Thu Dec 04, 2014 8:11 pm

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.
Shortcuts usually aren't...

verm
Posts: 4
Joined: Mon Dec 01, 2014 5:04 pm

Re: Accessing Excel Data in VB.net

Post by verm » Thu Dec 04, 2014 10:28 pm

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
?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Accessing Excel Data in VB.net

Post by krstcs » Thu Dec 04, 2014 10:38 pm

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.
Shortcuts usually aren't...