Can I change the code template for usercode module

Class library usage, coding and language questions.
orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Can I change the code template for usercode module

Post by orbistest » Fri Mar 22, 2013 9:54 am

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Can I change the code template for usercode module

Post by Support Team » Mon Mar 25, 2013 4:17 pm

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)

User avatar
Florent
Posts: 67
Joined: Wed Jul 04, 2012 3:31 pm
Location: Amiens / France

Re: Can I change the code template for usercode module

Post by Florent » Wed Mar 27, 2013 5:33 pm

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
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Can I change the code template for usercode module

Post by Support Team » Thu Mar 28, 2013 1:58 pm

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)

User avatar
Florent
Posts: 67
Joined: Wed Jul 04, 2012 3:31 pm
Location: Amiens / France

Re: Can I change the code template for usercode module

Post by Florent » Thu Mar 28, 2013 4:48 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Can I change the code template for usercode module

Post by Ciege » Thu Mar 28, 2013 4:58 pm

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.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Florent
Posts: 67
Joined: Wed Jul 04, 2012 3:31 pm
Location: Amiens / France

Re: Can I change the code template for usercode module

Post by Florent » Fri Mar 29, 2013 5:11 pm

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

orbistest
Posts: 23
Joined: Mon Oct 17, 2011 5:31 pm

Re: Can I change the code template for usercode module

Post by orbistest » Fri Apr 19, 2013 4:59 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Can I change the code template for usercode module

Post by Ciege » Fri Apr 19, 2013 6:13 pm

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
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Can I change the code template for usercode module

Post by Support Team » Mon Apr 22, 2013 8:46 am

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

Hermch
Posts: 40
Joined: Thu May 26, 2011 7:17 am
Location: Germany

Re: Can I change the code template for usercode module

Post by Hermch » Tue Apr 30, 2013 8:10 am

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.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Can I change the code template for usercode module

Post by Ciege » Tue Apr 30, 2013 3:58 pm

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.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Florent
Posts: 67
Joined: Wed Jul 04, 2012 3:31 pm
Location: Amiens / France

Re: Can I change the code template for usercode module

Post by Florent » Wed Jul 24, 2013 9:12 am

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