Source language: Translate to:

Using the [self] variable

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Using the [self] variable

Postby dpayer » Wed Mar 30, 2016 6:53 am

In an effort to clean up a listbox function I made, I want to be able to call the function using only the name of the listbox and not insert the variables that define initially the list contents or the selected item content.

As a test, I name the List Items variable as [[self]contents]
the selected item variable is [[self]selecteditem]

When I add items to this listbox, and then select an item and look in the debugger, it shows the name of the variable of the selected item as "selecteditem" without the name of the list box as part of the variable name. (I expected to see: listbox3selecteditem as the variable name.)

But, if I put in the doubleclick section of the actions the following: Alertbox "test" "[self]"

and then I double click on the listbox, it displays the name of the listbox as expected.

Image

At what point does the [self] variable get populated?

Test this by creating a new pub and pasting these objects into it:
Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=5
Name=Rectangle7
X=240
Y=20
W=221
H=454
Anchor=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=13418448
FillPattern=0
TabOrder=3
ObjectType=10
Name=ListBox3
X=245
Y=57
W=208
H=268
Anchor=0
Text=[[self]contents]
VarName=[[self]selecteditems]
VarType=0
MultiSelect=Yes
XPTheme=Yes
DblClick=Alertbox "test" "[self]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=9
Name=TextEntry4
X=248
Y=331
W=202
H=86
Anchor=0
VarName=[TextEntry3]
Align=1
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=7
ObjectType=8
Name=Text5
X=250
Y=25
W=197
H=24
Anchor=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 MS Sans Serif;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs28\cf0 ListBox3}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=11
ObjectType=3
Name=PushButton38
X=312
Y=424
W=97
H=32
Anchor=0
Text=Add to listbox3
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=ListBoxAddItem "ListBox3" "0" "[TextEntry3]"¶SetVar "[TextEntry3]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=15
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Using the [self] variable

Postby Gaev » Wed Mar 30, 2016 7:35 am

David Payne:

At what point does the [self] variable get populated?

From the Help file ...
[Self]
The name of the object that executed the currently running Action script. For scripts not executed by objects (such as page enter/exit), [Self] will be empty.

Guessing that this is related to your quest here ... which is in turn related to your quest for making new/improved ListBox related Functions ... may I suggest that you just ask users to specify the required variables in their Calls to your Functions e.g. ...
Code: Select all
Call "someFunction" "ListboxXYZ" "name of content variable" "name of variable for selected item" "selection type" etc. etc.
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Using the [self] variable

Postby virger » Wed Mar 30, 2016 7:45 am

Vieron este post ??, Tomen el ejemplo y ejecutenlo.
You saw this post?, Take the example and run.

http://www.neosoftware.com/community/viewtopic.php?f=2&t=21580

Bye Jamaica...
Hello Russian
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Using the [self] variable

Postby virger » Wed Mar 30, 2016 8:17 am

No entiendo, aqui no veo diferencia alguna.
He ajustado un poco su codigo, por favor ejecutelo.

I do not understand, here I do not see any difference.
I've tweaked a bit your code, please run it.

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=5
Name=Rectangle7
X=236
Y=12
W=272
H=454
Anchor=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=13418448
FillPattern=0
TabOrder=3
ObjectType=10
Name=ListBox3
X=241
Y=49
W=130
H=268
Anchor=0
Text=[[self]contents]
VarName=[[self]selecteditems]
VarType=0
MultiSelect=Yes
XPTheme=Yes
DblClick=Alertbox "test" "[self]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=9
Name=TextEntry4
X=244
Y=323
W=257
H=86
Anchor=0
VarName=[TextEntry3]
Align=1
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=8
Name=Text5
X=246
Y=17
W=259
H=24
Anchor=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 MS Sans Serif;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs28\cf0 ListBox3\plain\f0\fs16\cf0 \tab \tab \tab \tab \tab \tab \plain\f0\fs28\cf0 \tab Virger}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=5
ObjectType=3
Name=PushButton38
X=279
Y=418
W=193
H=32
Anchor=0
Text=Add to listbox3 & Virger
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=ListBoxAddItem "ListBox3" "0" "[TextEntry3]"¶ListBoxAddItem "Ls2" "0" "[TextEntry3]"¶SetVar "[TextEntry3]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=10
Name=Ls2
X=373
Y=49
W=130
H=268
Anchor=0
Text=[lista]
VarName=[data]
VarType=0
MultiSelect=Yes
XPTheme=Yes
DblClick=Alertbox "test" "[self]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=1


Le ganamos a Jamica.
We beat Jamaica.
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Using the [self] variable

Postby mishem » Wed Mar 30, 2016 9:23 am

Maybe so?

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=5
Name=Rectangle7
X=240
Y=20
W=221
H=454
Anchor=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=13418448
FillPattern=0
TabOrder=2
ObjectType=10
Name=ListBox3
X=245
Y=57
W=208
H=268
Anchor=0
Text=[selecteditems]
VarName=[[C]selecteditems]
VarType=0
MultiSelect=Yes
XPTheme=Yes
ObjEnterAction=SetVar "[C]" "[Self]"
ObjExitAction=SetVar "[C]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=9
Name=TextEntry4
X=248
Y=331
W=202
H=86
Anchor=0
VarName=[TextEntry3]
Align=1
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=8
Name=Text5
X=251
Y=25
W=197
H=24
Anchor=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 MS Sans Serif;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs28\cf0 ListBox3}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=5
ObjectType=3
Name=PushButton38
X=312
Y=424
W=97
H=32
Anchor=0
Text=Add to listbox3
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=ListBoxAddItem "ListBox3" "0" "[TextEntry3]"¶SetVar "[TextEntry3]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=MS Sans Serif
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
mishem
 
Posts: 576
Joined: Mon Oct 08, 2012 1:51 pm

Re: Using the [self] variable

Postby dpayer » Wed Mar 30, 2016 12:15 pm

Virger, this is a separate question from the other post. I am asking something about the [self] variable.

I did look at your example that addressed another question. Your example is based on already knowing the variable and resetting it. I wanted to find the name of the variable programmatically without knowing before hand. For example: If I know the listbox's name ONLY, without knowing anything else, tell me what the selected value's variable name is. Can you do that?

As an alternative, I am looking at a way to use the [self] variable. But that is a separate question.

David


virger wrote:Vieron este post ??, Tomen el ejemplo y ejecutenlo.
You saw this post?, Take the example and run.

http://www.neosoftware.com/community/viewtopic.php?f=2&t=21580

Bye Jamaica...
Hello Russian
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Using the [self] variable

Postby mishem » Wed Mar 30, 2016 12:56 pm

Can you do that?

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=10
Name=ListBox1
X=34
Y=44
W=198
H=361
Anchor=0
Text=1¶2
VarName=[ListBox1]
VarType=0
XPTheme=Yes
ObjAction=AlertBox "" "[Name]"
ObjEnterAction=GoSub "Self"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=2
ObjectType=10
Name=ListBox2
X=360
Y=52
W=228
H=372
Anchor=0
Text=1¶2
VarName=[ListBox2]
VarType=0
XPTheme=Yes
ObjAction=AlertBox "" "[Name]"
ObjEnterAction=GoSub "Self"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=3
mishem
 
Posts: 576
Joined: Mon Oct 08, 2012 1:51 pm

Re: Using the [self] variable

Postby mishem » Wed Mar 30, 2016 1:02 pm

Even easier.

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=10
Name=ListBox1
X=34
Y=44
W=198
H=361
Anchor=0
Text=1¶2
VarName=[ListBox1]
VarType=0
XPTheme=Yes
ObjAction=SetVar "[Name]" "ListBox1"¶AlertBox "" "ListBox1=[ListBox1]"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=2
ObjectType=10
Name=ListBox2
X=360
Y=52
W=228
H=372
Anchor=0
Text=1¶2
VarName=[ListBox2]
VarType=0
XPTheme=Yes
ObjAction=SetVar "[Name]" "ListBox2"¶AlertBox "" "ListBox1=[ListBox2]"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=3
mishem
 
Posts: 576
Joined: Mon Oct 08, 2012 1:51 pm

Re: Using the [self] variable

Postby dpayer » Wed Mar 30, 2016 1:20 pm

mishem wrote:
Can you do that?


Mishem, you misunderstand me also. (BTW, your objects in first example require a subroutine that is missing)

Show me action code for a subroutine that for any listbox I can do this:

SetVar "[nameoflistbox]" "Listbox1" (or whatever name it is)
GoSub Something
Alertbox "Test" "The name of the selected item variable is: [selecteditemvariableNAME]"
Alertbox "Test" "The name of the variable used for initial content is: [initialcontentvariableNAME]"
----
WITHOUT already knowing the name of those variables. Doing something similar to a GetObjectInfo type of query.

But this doesn't answer my question about the nature of the [self] variable. When is it activated?
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Using the [self] variable

Postby mishem » Wed Mar 30, 2016 1:54 pm

(BTW, your objects in first example require a subroutine that is missing)

Code: Select all
:Self
    SetVar "[Name]" "[Self]"
Return


SetVar "[nameoflistbox]" "Listbox1" (or whatever name it is)
GoSub Something
Alertbox "Test" "The name of the selected item variable is: [selecteditemvariableNAME]"
Alertbox "Test" "The name of the variable used for initial content is: [initialcontentvariableNAME]"


Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=10
Name=ListBox1
X=50
Y=29
W=211
H=399
Anchor=0
Text=[nameoflistbox]
VarName=[ListBox1]
VarType=0
XPTheme=Yes
ObjAction=SetVar "[selecteditemvariableNAME]" "[Self]"¶SetVar "[initialcontentvariableNAME]" "[ListBox1]"¶Alertbox "Test" "The name of the selected item variable is: [selecteditemvariableNAME]"¶Alertbox "Test" "The name of the variable used for initial content is: [initialcontentvariableNAME]"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=2
ObjectType=10
Name=ListBox2
X=333
Y=36
W=249
H=391
Anchor=0
Text=[nameoflistbox]
VarName=[ListBox2]
VarType=0
XPTheme=Yes
ObjAction=SetVar "[selecteditemvariableNAME]" "[Self]"¶SetVar "[initialcontentvariableNAME]" "[ListBox2]"¶Alertbox "Test" "The name of the selected item variable is: [selecteditemvariableNAME]"¶Alertbox "Test" "The name of the variable used for initial content is: [initialcontentvariableNAME]"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=3
ObjectType=3
Name=PushButton2
X=243
Y=439
W=129
H=35
Anchor=0
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SetVar "[nameoflistbox]" "1[#13]2[#13]3[#13]4"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=4


When is it activated?

When you initialize the object. At the beginning.
mishem
 
Posts: 576
Joined: Mon Oct 08, 2012 1:51 pm

Re: Using the [self] variable

Postby mishem » Wed Mar 30, 2016 2:05 pm

OR
subroutine

Code: Select all
:Self
    SetVar "[selecteditemvariableNAME]" "[Self]"
    SetVar "[initialcontentvariableNAME]" "[[Self]]"
    Alertbox "Test" "The name of the selected item variable is: [selecteditemvariableNAME]"
    Alertbox "Test" "The name of the variable used for initial content is: [initialcontentvariableNAME]"
Return


Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5,80
ObjectType=10
Name=ListBox1
X=50
Y=29
W=211
H=399
Anchor=0
Text=[nameoflistbox]
VarName=[ListBox1]
VarType=0
XPTheme=Yes
ObjAction=GoSub "Self"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=2
ObjectType=10
Name=ListBox2
X=333
Y=36
W=249
H=391
Anchor=0
Text=[nameoflistbox]
VarName=[ListBox2]
VarType=0
XPTheme=Yes
ObjAction=GoSub "Self"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=3
ObjectType=3
Name=PushButton2
X=243
Y=439
W=129
H=35
Anchor=0
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SetVar "[nameoflistbox]" "1[#13]2[#13]3[#13]4"
LineColor=16766935
LineWidth=1
LineStyle=6
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=204
TextColor=0
TabOrder=4
mishem
 
Posts: 576
Joined: Mon Oct 08, 2012 1:51 pm

Re: Using the [self] variable

Postby Gaev » Wed Mar 30, 2016 6:10 pm

David Payne:

But this doesn't answer my question about the nature of the [self] variable. When is it activated?

In all the commotion, you might have missed my response above i.e. as it states in the Help file, the value of the [self] variable is only available to script commands within the Action Events of a particular object.

So your generic subroutine/function can only obtain this value if it was GoSub/Call 'ed from within these Action Events ... again, from the Help file ...
Both List and Combo Boxes support the following Action Events: Selection Changed, Mouse Enter and Mouse Exit. In addition, List Boxes support Right Click and Double Click actions.
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Using the [self] variable

Postby dpayer » Thu Mar 31, 2016 6:18 am

Sorry Gaev,

I did miss your original post. That does clear it up. Thanks.

I will change my function to have the necessary details in the call.

Working on it now.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Using the [self] variable

Postby dpayer » Fri Apr 08, 2016 7:53 am

Gaev wrote:David
Guessing that this is related to your quest here ... which is in turn related to your quest for making new/improved ListBox related Functions ... may I suggest that you just ask users to specify the required variables in their Calls to your Functions e.g. ...
Code: Select all
Call "someFunction" "ListboxXYZ" "name of content variable" "name of variable for selected item" "selection type" etc. etc.


Gaev, I've created a new listbox function with a built in menuing system.

viewtopic.php?f=22&t=21587

Thanks for your input.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron