You Are Here:

Community: Developer Discussion Boards

#1 Old How to get value of variable from it's name - 2009-01-31, 03:12

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Sorry,

Too late to think, so I'll ask and hope for the best:

I can easily generate text string name of a variable, for example "variable42". How do I get the value of such variable, using that text string:

variable42 = 12
variableName = "variable42"
variable42 = 24
variableName = "variable42"

Is there an easy way? If not, then I'll avoid this problem by rewriting something...

Good night,

--jouni
Reply With Quote

#2 Old Re: How to get value of variable from it's name - 2009-01-31, 03:42

Join Date: Feb 2008
Posts: 743
Location: Belo Horizonte, Brazil
Send a message via Skype™ to Rafael T.
Rafael T.'s Avatar
Rafael T.
Offline
Forum Nokia Champion
Quote:
Originally Posted by JOM View Post
Sorry,

Too late to think, so I'll ask and hope for the best:

I can easily generate text string name of a variable, for example "variable42". How do I get the value of such variable, using that text string:

variable42 = 12
variableName = "variable42"
variable42 = 24
variableName = "variable42"

Is there an easy way? If not, then I'll avoid this problem by rewriting something...

Good night,

--jouni

Sorry, couldn't understand the question very well.

But, maybe the solution is using eval():

Code:
variable42 = 12
print eval("variable42") # prints 12
Hope I understood,

Rafael.
Reply With Quote

#3 Old Re: How to get value of variable from it's name - 2009-01-31, 14:42

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by Rafael T. View Post
Code:
variable42 = 12
print eval("variable42") # prints 12
Never used eval before, many thanx for the introduction !!!
However it's too late, I already rewrote that part of the code

Cheers,

--jouni who will have to take a good look at eval()
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a variable exported by a dll in a local variable: crash alban_c General Symbian C++ 5 2008-02-21 20:04
Strange Compilation error: fatal error: error writing to -: Invalid argument Evgeniz General Symbian C++ 4 2007-05-31 08:06
Parsing file content hendrawan.ashari General Symbian C++ 7 2007-03-09 11:41
load multiple images using 1 CFbsBitmap variable result in same image Rx-lee General Symbian C++ 1 2006-11-15 08:03
static variable problem plmanikandan General Symbian C++ 1 2005-01-30 03:29

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia