How do I determine variables associated with an object?

NeoBook tips, tricks, code samples and more...

Moderator: Neosoft Support

Locked
User avatar
agilefalcon
Posts: 11
Joined: Sat Jan 06, 2007 7:47 pm
Contact:

How do I determine variables associated with an object?

Post by agilefalcon »

I would like to create a generic subroutine that utilizes globally defined variable to pass the name of the calling object. The subroutine now has the name of the object with which to work: How do I obtain the name of the variable associated with the object?

I was hoping a built in function like GetObjectInfo would do this but it doesn't.
Any ideas how I can find the name of a variable (the variable named when an object is created).

thank you,
Chris
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Post by Gaev »

Chris:

I am not sure what you are looking for ... but try and insert ...

Code: Select all

AlertBox "Calling Object" "[self]"
... as the first command in your Subroutine.

If this is not what you were looking for ... perhaps you can explain with specific examples.
User avatar
agilefalcon
Posts: 11
Joined: Sat Jan 06, 2007 7:47 pm
Contact:

Post by agilefalcon »

Hello Gaev,
Oh, very good. I wasn't that familiar with the predefined variables such as [self]. So, that saved me a step of creating a variable for the calling object (hard coded).

So, now that I have determined the value of the [self] variable, in this case the object is "TextEntry1"

So, when I put the object on the form and it was given the object name of TextEntry1, it was also given the variable name APR. APR in my program will hold the interest rate. I am performing some validation of this field and other fields to ensure they are all numeric (without limiting them to 0-9 as a preformatted field). Therefore, 9.2 would be valid.

Since I would like this validation routine to be common to all fields in the program I want to put the routine in a single place and call it from each of the objects requiring validation. Therefore, I need to know the calling object so that I can clear or otherwise edit the variable that the contains the data (for that specific object) the user has entered.

Once I know the object (as determined by the [self] variable, how do I find the name of the variable associated with it.

What I find interesting is this:

{NeoBook 5 Objects}
NeoBookVer=5.60
ObjectType=9
Name=TextEntry1
X=8
Y=8
W=80
H=24
Anchor=0
Hint=Enter Annual Percentage Rate
VarName=[APR]
EditLen=0

In the above, I have copied and pasted the object into my Notepad (text editor). Lo and behold, the variable is enumerated there: "VarName=[APR]"

How do I retrieve this and use it in my program?

Thank you!

Chris.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Post by Gaev »

Chris:

I don't think the Object Name is relevant for what you are attempting to do.

A simple technique would be to ...

Code: Select all

SetVar "[Var_Routine]" "[APR]"
GoSub "Routine"
SetVar "[APR]" "[Var_Routine]"
... and use a different variable (in place of [APR]) when calling it from another Text Entry Object.

Also helps to maintain a discipline where the Object Name (which you can also rename) matches the associated Variable Name.

But a better way is to use Functions instead of Subroutines ... where you can pass Variable Names as parameters.
Locked