PDA

View Full Version : Get name of a variable as string?


f97ao
02-19-2006, 10:56 AM
Hiya,

Is there a way to get a name of a variable as a string?

So for example GetName(MyVariable) would return "MyVariable"

This would be very handy for saving information down to disk.

/Andreas

JHaywood
02-19-2006, 02:25 PM
Can't you just use "as string"?

(GetName(MyVariable)) as string

f97ao
02-19-2006, 02:30 PM
Can't you just use "as string"?
(GetName(MyVariable)) as string

Nope, that doesn't work. :) That will convert the value of the variable into a string. But I want to get the actual variable name.

for example

test=10
getname(test) will return "test"
if i write:
test as string it will return "10"

I would use this to save variable values into ini files.
/Andreas

Bobo
02-19-2006, 02:45 PM
Nope, that doesn't work. :) That will convert the value of the variable into a string. But I want to get the actual variable name.

for example

test=10
getname(test) will return "test"
if i write:
test as string it will return "10"

I would use this to save variable values into ini files.
/Andreas


I don't see the usefulness of this. If you could write getname(test), you would HAVE TO TYPE IN test, so how difficult it is the write "test" instead?

Where are you getting the variables from? How are you getting the variables? Is it procedural approach or do you explicitly write each variable being saved to INI file?

f97ao
02-19-2006, 03:09 PM
I don't see the usefulness of this. If you could write getname(test), you would HAVE TO TYPE IN test, so how difficult it is the write "test" instead?


Hiya bobo,
Here is an exact example of how I do right now:

IniClass.Update "Lock" &Lock saveOrLoad

Notice that I first have to write the name of the variable "Lock"
then I send in the variable Lock. The SaveOrLoad is either true or false if it loads or saves the file into an ini file.

What I would like to do is just skip the first variable so it says this instead
IniClass.Update &Lock saveOrLoad

I must have the name when I write in the ini file to identify the variable, it says something like this in the ini file:
LockWindows=true


Where are you getting the variables from? How are you getting the variables? Is it procedural approach or do you explicitly write each variable being saved to INI file?

I load/save them manually. Since I'm saving/loading hundreds of variables it would be nice to save some manual typing, but you are right it's not extremely important. However I can imagine other uses, like debugging.

/Andreas

d3coy
02-22-2006, 04:56 AM
Hey Andreas,

Shouldn't this work?

((#x)as string)

where x is the variable you want the name of as a string

CGTalk Moderation
02-22-2006, 04:56 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.