Page 1 of 1

How to use "_this"

Posted: Wed Dec 01, 2010 2:32 pm
by EViews Esther
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.

Re: How to use "_this"

Posted: Wed Apr 14, 2021 12:41 am
by CrisisStudent
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.

Re: How to use "_this"

Posted: Wed Apr 14, 2021 8:08 am
by EViews Gareth
Unfortunately not - there is no way to name an unnamed object. That's why _this is provided.

Re: How to use "_this"

Posted: Wed Apr 14, 2021 8:19 am
by CrisisStudent
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.