Page 1 of 1

Common function to call from different recording modules

Posted: Thu Oct 20, 2016 5:48 pm
by rastek
Hi,
I need a common Sub how can I do that ?
Lets I have function in user code and I want to call it from different modules, how can I do that ? Currently I can only call functions from its recording module.

Re: Common function to call from different recording modules

Posted: Thu Oct 20, 2016 6:06 pm
by odklizec
Hi,

You can achieve this by 'inheritance'. You can find a very nice tutorial with description in this blog post...
http://www.ranorex.com/blog/custom-smar ... readAction

Re: Common function to call from different recording modules

Posted: Fri Oct 21, 2016 8:54 am
by rastek
Isn there any other way instead of creating a class ? Does has to be object oriented ?

Re: Common function to call from different recording modules

Posted: Fri Oct 21, 2016 9:03 am
by odklizec
Hi,

What's the problem with suggested "common" class and inheritance? It's pretty easy to setup and use. I don't know about any other way to achieve what you've requested.

Re: Common function to call from different recording modules

Posted: Tue Oct 25, 2016 2:09 pm
by Vaughan.Douglas
I agree that using class inheritance is overkill for something so simple as a common module, but Ranorex doesn't seem to allow you to import from modules.

A potential work around is to add a module.
sharedSub.png
Added your sub to the module you just created. We'll call the sub "EatCheese".

Code: Select all

Public Module Module1
	Public Sub EatCheese
		'Do stuff
	End Sub
End Module
Then in the recorded module, you'll add a new usercode step called "PointsToEatCheese"
pointsto.png
Then in the usercode file you'll call "EatCheese" directly

Code: Select all

	Public Partial Class Recording1
		
		''' <summary>
		''' This method gets called right after the recording has been started.
		''' It can be used to execute recording specific initialization code.
		''' </summary>
		Private Sub Init()
			' Your recording specific initialization code goes here.
		End Sub
		
		Public Sub PointsToEatCheese()
			EatCheese()
		End Sub
		
	End Class
The IDE is smart enough that the EatCheese sub in the shared module will appear in the IntelliSense.
IntelliSense.png
You'll just want to make sure your signatures match in both cases so you can appropriately pass arguments between the usercode step and the shared module sub.

Unfortunately I don't know of a way to get "EatCheese" to be listed in the available coded steps when you try to add a coded step from the recorded module UI directly. If that is a requirement, you'll probably need to stick to the inheritance method or submit a feature request to the powers that be.

Re: Common function to call from different recording modules

Posted: Sat Nov 05, 2016 3:44 am
by rastek
Tans Vaughan, that really helped !

Re: Common function to call from different recording modules

Posted: Tue Nov 08, 2016 1:12 pm
by Vaughan.Douglas
No problem. Glad I could help.

Re: Common function to call from different recording modules

Posted: Mon Dec 05, 2016 3:07 pm
by Vaughan.Douglas
Updating this thread with new information. Ranorex 6.2 has incorporated this functionality into the tool.