Use variable in C# script

Ranorex Studio, Spy, Recorder, and Driver.
romainb25
Posts: 15
Joined: Mon May 09, 2016 2:31 pm

Use variable in C# script

Post by romainb25 » Mon May 23, 2016 10:18 am

Hi community,

I have a recording called "TestCase1" linked to and Excel File by an Excel Data Connector called "TestCase1.xls"
I create three variables in test case : name ,hasPhoneNumber and phoneNumber

There is the xls view :
id | name | hasPhoneNumber | phoneNumber
1| romain | yes | 0606060606
2 | paul | no |
3 | jacques | yes | 0505050505

In my script, i would like to have the same code as this:
for(i=1,i<3,i++)
{
if(hasPhoneNumber = "yes")
{
getPhoneNumber();
}
else if(hasPhoneNumber = "no")
{
text : No phone number for this people!
}
}

Can i use a variable and get his value in a C# script?

Thanks

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Use variable in C# script

Post by odklizec » Mon May 23, 2016 11:15 am

Hi,

Are you using code module or recording module?

In case of Code Module, you will have to create variable "hasPhoneNumber", via context (right-click) menu >> Insert New Module Variable option. Then simply connect the variable with data connector.

If you are using Recording Module, you can create new variable (in UserCode file) via Variables dialog.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

romainb25
Posts: 15
Joined: Mon May 09, 2016 2:31 pm

Re: Use variable in C# script

Post by romainb25 » Tue May 24, 2016 11:29 am

Thanks @odklizec : it works!