Page 1 of 1

Make var declared in User Code accessible to parameters?

Posted: Mon Aug 12, 2013 1:51 pm
by kmck
I am trying to get an int variable declared within a user code action (not module) to be accessible for parameter binding so I can access that variable's value in another recording.

I was able to do this for a new code module by declaring the variable in the constructor, but since the user code actions use partial classes, I am not sure how I would be able to get a variable created within that user code action to be accessible by other recordings.

I have attempted to include the following in the partial class:

Code: Select all

public partial class ChangeSortOrder
{
    public int newSortOrder {
            get { return newSortOrder; }
            set{ newSortOrder = value; }
}
But when I try to bind it to a parameter, it doesn't show in the dropdown list of module variables.

Any way that I can achieve this?

Re: Make var declared in User Code accessible to parameters?

Posted: Tue Aug 13, 2013 3:25 pm
by kmck
Have I stumped everyone? :lol:

Re: Make var declared in User Code accessible to parameters?

Posted: Tue Aug 13, 2013 4:37 pm
by odklizec
Hi,

I think the problem is in the fact that User Codes currently accept only string parameters...
http://www.ranorex.com/forum/missing-me ... tml#p20338

Hope this helps? ;)

Re: Make var declared in User Code accessible to parameters?

Posted: Tue Aug 13, 2013 8:32 pm
by Support Team
kmck wrote:Any way that I can achieve this?
You just need to add the TestVariable attribute to the property with a unique ID as parameter. In user code modules you can also right click in the code editor and select "Insert Module Variable" (see the associated documentation:
string _UserCodeVar = "value";
[TestVariable("90BF060B-6939-4FD4-AD41-C34DECB49DE0")]
public string UserCodeVar
{
    get { return _UserCodeVar; }
    set { _UserCodeVar = value; }
}
Regards,
Alex
Ranorex Team