WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-08-2007, 09:33 AM
WebProWorld New Member
 

Join Date: Dec 2006
Posts: 15
montyauto RepRank 0
Default Can I get a variable name as a string?

how do i get a variable name as a string e.g i have a variable
myvar:1 2 5 3 2 6 7 8
i want to get "myvar"
Reply With Quote
  #2 (permalink)  
Old 01-08-2007, 04:02 PM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 380
southplatte RepRank 1
Default

might probably depend upon the language you are using whether or not you can do that, and if so what the syntax for doing it would be.

What language are you programming in?
Reply With Quote
  #3 (permalink)  
Old 01-08-2007, 06:34 PM
WebProWorld Pro
 

Join Date: Sep 2005
Location: Manchester, UK
Posts: 257
mikesmith76 RepRank 0
Default

I'm probably going mad here but I can't get my head around what you're trying to do. Your saying you have a variable $var and want to get the name of it???

:|
Reply With Quote
  #4 (permalink)  
Old 01-09-2007, 07:37 AM
WebProWorld New Member
 

Join Date: Dec 2006
Posts: 15
montyauto RepRank 0
Default

Quote:
Originally Posted by mikesmith76
I'm probably going mad here but I can't get my head around what you're trying to do.

Your saying you have a variable $var and want to get the name of it???
Correct!
For instance we have some variables that only have a value after we run a subroutine which value also could be defined after do another subroutine. I want to know which variable has assigned to that certain value.

Can we or not?

So far I do check my list of variables one by one, making my program a bit complicated and long running, troublesome if I put a new variable and forgot to put in my variable list.

Is there any function to get the name of a variable based on its value?

Quote:
Originally Posted by southplatte
might probably depend upon the language you are using whether or not you can do that, and if so what the syntax for doing it would be.

What language are you programming in?
Any languange please, php, perl, phyton whatever that don't make you mad.
Reply With Quote
  #5 (permalink)  
Old 01-09-2007, 08:58 AM
DaveSawers's Avatar
WebProWorld Veteran
 

Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 354
DaveSawers RepRank 1
Default

Quote:
Originally Posted by montyauto
Is there any function to get the name of a variable based on its value?

Any languange please, php, perl, phyton whatever that don't make you mad.
Basically, no.

It would surely be nonsensical to do so. Lets say you had some code that ended up with:

x=3
y=2
z=3

and you asked for the name of a variable with a value of 3. What would you expect to get? And what would you do with the result anyway?

Perhaps if you describe what it is you are trying to do at a higher level, you will get a meaningful response that will show you how to achieve the end result you want without having to find which variables have values.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #6 (permalink)  
Old 01-09-2007, 09:16 AM
WebProWorld Pro
 

Join Date: Sep 2005
Location: Manchester, UK
Posts: 257
mikesmith76 RepRank 0
Default

I've read a similar question recently on another forum and the answer was no. In subroutines / functions / whatever all the variables are usually defined in the local scope. After that function has finished executing the variables contained within it no longer exist.

I think you need to rethink what you are trying to acomplish, there has to be an easier way to do it
Reply With Quote
  #7 (permalink)  
Old 01-10-2007, 03:21 PM
WebProWorld Pro
 

Join Date: Sep 2006
Location: Hawai'i
Posts: 166
Dinghus RepRank 0
Default I can see a use for this

I can see where you might want to do something like this ie assign values to variables and then find out which variable rec'd the value. HOWEVER, to retrieve the NAME of the variable that has the value is done either by catching it when it is assigned or going through each variable looking for the value. Then you have to store the variable name in another variable.

I'm just taking a wild guess here based on 30+ years of programming experience, but there is probably a better way to do what you are trying to do, whatever it is.

If you can give us a better description of what you are trying to accomplish it would help.

And honest, none of us will steal your idea. ;)
Reply With Quote
  #8 (permalink)  
Old 01-10-2007, 05:33 PM
WebProWorld Pro
 

Join Date: Sep 2005
Location: Manchester, UK
Posts: 257
mikesmith76 RepRank 0
Default

Quote:
I can see where you might want to do something like this ie assign values to variables and then find out which variable rec'd the value.
But surely if you've assigned a value to a variable you already know which variable this is? Or am i misunderstanding your statement?

I think we really need to hear what the original poster had in mind before we can give out any more advice.
Reply With Quote
  #9 (permalink)  
Old 01-10-2007, 09:08 PM
WebProWorld New Member
 

Join Date: Dec 2006
Posts: 15
montyauto RepRank 0
Default

Quote:
Originally Posted by DaveSawers

Basically, no.

It would surely be nonsensical to do so. Lets say you had some code that ended up with:

x=3
y=2
z=3
The values is unique.

My question is simple:

myvar:1 2 5 3 2 6 7 8
i want to get "myvar"

Pls give me simple answer : "can" or "cannot".

If not possible then fine, I'll forget about it and find another way..
Reply With Quote
  #10 (permalink)  
Old 01-11-2007, 08:24 AM
WebProWorld Pro
 

Join Date: Sep 2005
Location: Manchester, UK
Posts: 257
mikesmith76 RepRank 0
Default

The answer is no. As said previously if you want help finding another way around your problem post specific details.
Reply With Quote
  #11 (permalink)  
Old 01-11-2007, 02:44 PM
WebProWorld Pro
 

Join Date: Sep 2006
Location: Hawai'i
Posts: 166
Dinghus RepRank 0
Default Clarification

I did say you could capture the variable name when you assigned the value to it.

Back to the "easy" question. No, your question is NOT easy. It is too vague.

Yes, you can get the variable name, but that would appear to be the hard way of whatever you are doing.
Reply With Quote
  #12 (permalink)  
Old 01-12-2007, 07:47 AM
WebProWorld New Member
 

Join Date: Dec 2006
Posts: 15
montyauto RepRank 0
Default Re: Clarification

Quote:
Originally Posted by Dinghus
Yes, you can get the variable name, but that would appear to be the hard way of whatever you are doing.


What ever hard the way it is, I would like to know, I really curious cause no one give a positive reply since I posted this question.
Reply With Quote
  #13 (permalink)  
Old 01-18-2007, 05:20 PM
WebProWorld Pro
 

Join Date: Sep 2006
Location: Hawai'i
Posts: 166
Dinghus RepRank 0
Default I did

I told you how to capture the variable name.

You either grab it when you insert the value into the variable or you query each variable until you find the one that has the value you are looking for.

But what would be the purpose of doing that? I'm sure there is a better way of doing whatever it is you are trying to do.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , ,



Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0