Page 1 of 1

Can I change the code template for usercode module

Posted: Fri Mar 22, 2013 9:54 am
by orbistest
I have built a usercode library and I inherit the module class so that users can add a usercode line to the recordings and select the function they want from the drop-down.

e.g. the Generic code library is declared
Public Class GenericUserCode
#Region "Global Functions"

Public Sub CreateEntry( EntryName as String)
...
End Sub
#End Region

The Usercode module (manually edited) is

Public Partial Class CreateStartingPosition
Inherits GenericUserCode
...
End Class


I would like the bit which is underlined to be added whenever a new recording module (rxrec) is added.
Is this possible? I cannot find it in the Options\templates . I use VB.NET (as you can see from the syntax).

Thanks,
OrbisTest

Re: Can I change the code template for usercode module

Posted: Mon Mar 25, 2013 4:17 pm
by Support Team
Hello,

It is possible to create a template for a User Code module that inherits a custom base class.
You would need to adjust the template that is stored in the following location:

Code: Select all

C:\Program Files (x86)\Ranorex 4.0\RanorexStudio\AddIns\AddIns\Misc\RxSharpdevelop\Templates\Files\VBNet\UserCodeModule.xft
Currently, it's not possible to use a custom base class for a Recording module to use its methods.
I have forwarded your feature request to our development team.

Regards,
Markus (T)

Re: Can I change the code template for usercode module

Posted: Wed Mar 27, 2013 5:33 pm
by Florent
it could be heplfull for me
i try to customize the file but i get the error below
apparently i've put my own code in a wrong place in the file
where must we put the custom code ?
Thank you to give us precision about that tip
2013-03-27_172612.jpg

Re: Can I change the code template for usercode module

Posted: Thu Mar 28, 2013 1:58 pm
by Support Team
Hello,

We don't recommend to change the template for a User Code module.
According to your error message, it seems that you try to use an invalid character in your custom template file at line 42 position 8.
What you want to do in your template?

Regards,
Markus (T)

Re: Can I change the code template for usercode module

Posted: Thu Mar 28, 2013 4:48 pm
by Florent
Hi Markus,

I want to add a few user code functions that i use for each module.

Each time i create a module, i have to add those functions.

To go faster, i've added this functions in tools/option/coding/code templates.

Have them in the template could be the best. I just want to know where can i put my few routine functions in the template.

Thanks

Re: Can I change the code template for usercode module

Posted: Thu Mar 28, 2013 4:58 pm
by Ciege
Jumping in here... Why not create a framework DLL that contains all you reusable methods. The make a reference to that DLL from each of your scripts. This way each test will have access to your methods whenever they need them. Further, if you have to make bug fixes, changes or even add new methods, all you have to do is work in the framework DLL then all your test scripts will automatically get the updated code.
The way you are working right now, yf you keep copying the same code in all your scripts, then need to make a change, you will have to visit each script individually to make that same change.

Re: Can I change the code template for usercode module

Posted: Fri Mar 29, 2013 5:11 pm
by Florent
Hi Ciege,

Thank you for your advice. It's a best practice.
I plan to apply it next week.
Otherwise, i don't think that functions added in the DLL will be directly accessible from a user code combobox of a module. I will have to add each needed function in the user code page before call it from a "user code" action of a module. That was my first purpose.

Have a nice weekend
Regards,
Florent

Re: Can I change the code template for usercode module

Posted: Fri Apr 19, 2013 4:59 pm
by orbistest
Please excuse me if I am missing something obvious but I am not a .net programmer.

I have written several re-useable functions (subs) and it seems that putting these into a DLL is s great idea. I know what a DLL is and I can see how to reference it from a project BUT I can't see how to take a .vb and make a DLL from it.

Please be gentle ... It's been a long week.

Thanks
orbistest

Re: Can I change the code template for usercode module

Posted: Fri Apr 19, 2013 6:13 pm
by Ciege
First, this depends on the IDE you are using (RanorexStudio or Visual Studio)...

Th big picture with Visual Studio you should create a new Class Library solution. Setup your namespace with whichever public classes you want. Your public methods live within the appropriate public classes. These are the methods that will be shared publicly when referencing the DLL...

I would suggest doing a Google search on how to create a DLL in the IDE of your choice or ask one of your developers to help you. It really is quite simple to create one once you've done it...

Here is a quick one I just found in a few seconds of Google searching: http://www.codeproject.com/Tips/319950/ ... ual-studio

Re: Can I change the code template for usercode module

Posted: Mon Apr 22, 2013 8:46 am
by Support Team
Let me jump into that discussion :D
Florent wrote:Otherwise, i don't think that functions added in the DLL will be directly accessible from a user code combobox of a module. I will have to add each needed function in the user code page before call it from a "user code" action of a module.
They will be accessible directly from the recorder UI view if you let the recording inherit from the class holding your utility methods. In other words: Create a utility class in a DLL or somewhere in your project; add a reference to the DLL containing your utility class; then edit the recording usercode file and let the recording inherit from the utility class. Now the utility methods should be visible in the recorder UI, too, if you create a user code action.

Let me know if that satisfies your needs. IMHO with that functionality, there should not be the need to change the usercode template any more.

Regards,
Alex
Ranorex Team

Re: Can I change the code template for usercode module

Posted: Tue Apr 30, 2013 8:10 am
by Hermch
Hi,

I think this sounds very intresting. Could someone please describe how to create such a DLL project with shared methods in Ranorex Studio? And how to use them from other projects?

Thanks in advance.

Re: Can I change the code template for usercode module

Posted: Tue Apr 30, 2013 3:58 pm
by Ciege
Hermch wrote:Hi,

I think this sounds very intresting. Could someone please describe how to create such a DLL project with shared methods in Ranorex Studio? And how to use them from other projects?

Thanks in advance.
As described above, first you need to create the DLL with your shared methods in it... Then, you make a reference to that library from your test(s) and you will have access to the shared methods.

Re: Can I change the code template for usercode module

Posted: Wed Jul 24, 2013 9:12 am
by Florent
Support Team wrote: Let me know if that satisfies your needs. IMHO with that functionality, there should not be the need to change the usercode template any more.
i tried
it's ok
that is what i was looking for :P
thanks a lot