How to use "_this"

For tips, questions and general information about writing Add-ins, how to package them, and how to submit them to EViews for publication.

Moderators: EViews Gareth, EViews Moderator

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

How to use "_this"

Postby EViews Esther » Wed Dec 01, 2010 2:32 pm

EViews 7.1 provides a new keyword _this which refers to the currently active object.

To illustrate the main idea, suppose that we have a series “x” which contains all ones:

Code: Select all

series x = 1

[E.g.1] _this can refer to the object that you lastly clicked on.
If you click on “x” in the workfile, _this denotes the “series” object.
Note that _this can be any object (such as coef, equation, group, etc.) you will choose in your workfile.

[E.g.2] When used in a program, _this refers to the active object at the time the program was initiated.
In particular, suppose we have the trivial (silly) program Myline.prg which consists of the command:

Code: Select all

_this.line

If you run this program, you will see the line for the series “x”.

Now, let us add the following lines (in Myline.prg):

Code: Select all

_this.line
series y = 2
_this.line

Do you see the line for the series “y”? No. :wink: We still see the line for the series “x” because _this refers to the initially opened object.

CrisisStudent
Posts: 30
Joined: Mon Nov 16, 2020 10:52 am

Re: How to use "_this"

Postby CrisisStudent » Wed Apr 14, 2021 12:41 am

Can one use _this command in some way to give name to the corresponding object if it is unnamed?

My situation is following: I have add-in that uses the name of _this (i.e. _this.@name) in its procedures. However, when the object is unnamed then _this.@name will return empty string, which then will lead to failure of the add-in (this can of course happen only in GUI execution). What I would need is to have a way to set the name of the unnamed object so that the add-in can proceed.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 12945
Joined: Tue Sep 16, 2008 5:38 pm

Re: How to use "_this"

Postby EViews Gareth » Wed Apr 14, 2021 8:08 am

Unfortunately not - there is no way to name an unnamed object. That's why _this is provided.
Follow us on Twitter @IHSEViews

CrisisStudent
Posts: 30
Joined: Mon Nov 16, 2020 10:52 am

Re: How to use "_this"

Postby CrisisStudent » Wed Apr 14, 2021 8:19 am

Thanks Gareth. Makes sense. I just ended up adding check if the name is empty, and using '"_this" if yes, so it is not a big deal in the end.


Return to “Add-in Writing area”

Who is online

Users browsing this forum: No registered users and 2 guests