April 23, 2024, 02:39:13 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


How do get the identifier for a variable and put that in a string variable?

Started by ACall, January 08, 2007, 11:17:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ACall

I am looking for a way to get at the identifier for a variable and somehow automatically put that in another string variable?

Let's say we have:



def VariableA as string
VariableA = "abcd"

ShowVarData("VariableA", VariableA)


sub ShowVarData(VarID as string, VarValue as string)
BoxData$ = VarID + " = " + VarValue
messagebox (null, BoxData$, "SomeTitle")
endsub



If we run the above code it will display the VariableId and the VariableValue in the message box.

Is there a way to only pass in VariableA into a revised ShowVarData sub and have it automatically inspect for the variable identifier?

Thanks...Archie


Ionic Wind Support Team

The name of the variable only exisits in your source code.  Once it is compiled into an executable the name isn't there anymore, it is just the address of memory.

Except of course in debug mode where global variables are actually named in the debug segment of the executable.  The names, however, are only accessable by a debugger and not by your code. 

Paul.
Ionic Wind Support Team


Jerry Muelver

Archie, depending on what you are actually doing with the variable and its value, you might be able to use a dictionary (associative array), and work the key/value pairs from that. Then, there's always pointers!  ::)

Rock Ridge Farm (Larry)

January 09, 2007, 06:14:20 AM #4 Last Edit: January 09, 2007, 06:19:26 AM by Rock Ridge Farm (Larry)
Declare a local var in the subroutine and return the value.
In the calling section set the value = the return code.
You would only need pass the initialue value once to the subroutine.

string a;
string a1;
.......
a = "ABC";

a1 = subcall(a);
a = a1;
}

sub subcall(string b) string {
b = b + "cde";
return(b);
}

ACall

Jerry,  I actually used the associative array technique before my post.  It works pretty good.

Larry,  I am not following you code?  Is it in Aurora, rather than eBASIC?