need variable contents, getting variable name

Results 1 to 3 of 3

Thread: need variable contents, getting variable name

  1. #1
    Join Date
    Dec 1969
    Posts
    569

    Default need variable contents, getting variable name

    i have a function that goes and does it&#039s thing, takes the parameter it is given, and concatinantes either a "0" or a "1" to the end of the value passed to it. the functions output will be the name of a predefined variable. the problem is that the function returns a string, i need the VALUE of that variable, not the variable name as a string.<BR><BR>simplified example:<BR><BR>function oneOrZero(something)<BR>oneOrZero = something & "1"<BR>end function<BR>&#060;% aName1 = "this is my contents" &#037;&#062;<BR>&#060;% thisVar = oneOrZero(aName) &#037;&#062;<BR>&#060;%= thisVar &#037;&#062;<BR><BR>right now it returns:<BR>aName1<BR><BR>i want it to return:<BR>this is my contents<BR><BR>i know i&#039m just missing something dumb :(<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: need variable contents, getting variable name

    YOUR CODE:<BR>===========<BR>function oneOrZero(something)<BR>oneOrZero = something & "1"<BR>end function<BR><BR>&#060;% aName1 = "this is my contents" &#037;&#062;<BR>&#060;% thisVar = oneOrZero(aName) &#037;&#062;<BR>&#060;%= thisVar &#037;&#062;<BR><BR>First off, you call the variable aName1, and then refer to it in the function call as aName. This is one reason why you shold *always* use Option Explicit (see http://www.4guysfromrolla.com/webtech/faq/Intermediate/faq6.shtml).<BR><BR>Second, are you sure you are saying:<BR>&#060;% thisVar = oneOrZero(aName) &#037;&#062;<BR><BR>not<BR>&#060;% thisVar = oneOrZero("aName") &#037;&#062;<BR><BR>??? I ran your code with the one change, and it worked fine. Let me know if you are still having problems. Thanks!<BR><BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    569

    Default RE: need variable contents, getting variable name

    actually, i realized that i made an error in the call to the function.<BR><BR>i used:<BR>&#060;%= fontOrCss("menu"))&#037;&#062;<BR><BR>i needed to use:<BR>&#060;%= eval(fontOrCss("menu"))&#037;&#062;<BR><BR>long live the love of eval()! :)

Posting Permissions

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