how can i pass a value from a procedure to actions table?

Ranorex Spy, Recorder, and Studio.
Tomsk666
Certified Professional
Certified Professional
Posts: 33
Joined: Thu Mar 28, 2013 12:59 pm
Location: UK
Contact:

how can i pass a value from a procedure to actions table?

Post by Tomsk666 » Thu Nov 27, 2014 3:09 pm

I have created a simple custom subroutine in a code module (called MyFuncs):

sub rowCount (ByRef varRowCount as Integer, myTable As ranorex.Adapter)
'Dim rowCount As Integer
varRowCount = myTable.Find(".//tr").Count()
report.Log(Ranorex.ReportLevel.Info, "User", "Table has " & varRowCount & " rows")

End sub

In my recording user code module I have inherited the code module that contains the above:

Public Partial Class Recording1
'TAM : Load our custom function library
inherits MyFuncs

Now when I go into Recording1 Actions Table, I can use the add new action button and call my user code sub.
I'm using a variable for the first parameter and passing a a web table object from the repository as the second parameter.
However, the variable from the actions table does not capture the value that should be passed back from the sub. The code definitely works as I can report out from the sub OK, but just cant pass the value back from the sub to the variable in the actions table that calls it.
Is this not possible?

here is the code created by Raborex behind the recording module Recording1:

rowCount(ValueConverter.ArgumentFromString(Of Integer)("varRowCount", varRows), repo.Forms.OutputTable)
Delay.Milliseconds(0)

Report.Log(ReportLevel.Info, "User", varRows, new RecordItemIndex(1))

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

Re: how can i pass a value from a procedure to actions table?

Post by Support Team » Fri Nov 28, 2014 2:47 pm

Hi Tom,

Module variables are just of type String, Ranorex therefore needs to cast them to Integer when you for instance use an int in your parameters and you therefore do not directly write to the module variable but to a internal one.
In order to change the value of the module variable you need to bypass the module variable directly (as String):
UserCodeString.png
UserCodeString.png (6.85 KiB) Viewed 1930 times
sub rowCount (ByRef varRowCount as String, myTable As ranorex.Adapter)
			varRowCount = Convert.ToString(myTable.Find(".//tr").Count())
			report.Log(Ranorex.ReportLevel.Info, "User", "Table has " & varRowCount & " rows")
		End sub
Regards,
Markus
.
Image

Tomsk666
Certified Professional
Certified Professional
Posts: 33
Joined: Thu Mar 28, 2013 12:59 pm
Location: UK
Contact:

Re: how can i pass a value from a procedure to actions table?

Post by Tomsk666 » Fri Nov 28, 2014 5:07 pm

Thanks Markus - that makes perfect sense! - I didn't realise module variables were only of type string.
I'll try it out

Tomsk666
Certified Professional
Certified Professional
Posts: 33
Joined: Thu Mar 28, 2013 12:59 pm
Location: UK
Contact:

Re: how can i pass a value from a procedure to actions table?

Post by Tomsk666 » Mon Dec 01, 2014 10:25 pm

Hi Markus,

All works fine in VB. I'm just trying it in C#, but having problems.
I've just changed the function to:

public void rowCount (Ranorex.Adapter myTable, out string varRowCount)
{
varRowCount = myTable.Find(".//tr").Count.ToString();
Report.Log(Ranorex.ReportLevel.Info, "User", "Table has " + varRowCount + " rows");
}


but if I use the 'out' or 'ref' keyword for the function parameter to pass the value back to the Actions Table, I get an error from Ranorex against the call in the recording code module
Any idea what I'm doing wrong? Im using 5.2.1

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

Re: how can i pass a value from a procedure to actions table?

Post by Support Team » Fri Dec 05, 2014 4:41 pm

Hi Tom,

You are right this doesn't work in C# since you would also need to add the "ref" to the Recording.cs file.
The only workaround I can think of is to use a local method which would then call the method of the base class, something like this:
public void rowCount(Ranorex.Adapter myTable)
		{
			// _varRowCount is the internal variable of the varRowCount property
			rowCountBaseMethod(ref _varRowCount, myTable);
			Report.Info(varRowCount);
		}
                
                //This is the method specified in the base class
		public void rowCountBaseMethod(ref string varRowCount, Ranorex.Adapter myTable)
		{
			varRowCount = Convert.ToString(myTable.Find(".//tr").Count);
			Report.Log(Ranorex.ReportLevel.Info, "User", "Table has " + varRowCount + " rows");
			
		}
Please also share the solution Roland discussed with you, to help others in the same situation.

Thanks,
Markus
.
Image