Type of module variables

Ask general questions here.
Karlsruhe87
Posts: 8
Joined: Wed Apr 08, 2015 12:26 pm

Type of module variables

Post by Karlsruhe87 » Thu Apr 16, 2015 8:23 am

I try to change the type of a module variable from String (default) to Int32.

I know I could change it if I use the variable as argument in a method via F4, but I assign the value to the variable via return from the method. When I click F4 on this piece of usercode, it shows me the variable, but no choice to change the type of the variable. The returntype of the method is also int.

When I run the method it tells me you can't convert from Int to String which is logic, but where can I change the type of a module variable never used as argument in a method?

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

Re: Type of module variables

Post by odklizec » Thu Apr 16, 2015 8:44 am

Hi,

I'm afraid, the module variables are, by design, always "strings". The only way to achieve what you want is to convert the string variable to int prior using it in your method. You can do this for example by using Int32.Parse or Int32.TryParse.

Code: Select all

//Parse
int varOut = Int32.Parse(moduleVar);

//TryParse
bool result = Int32.TryParse(moduleVar, out varOut);
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