Page 1 of 1

Type of module variables

Posted: Thu Apr 16, 2015 8:23 am
by Karlsruhe87
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?

Re: Type of module variables

Posted: Thu Apr 16, 2015 8:44 am
by odklizec
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);