Link to home
Start Free TrialLog in
Avatar of nistmaru
nistmaru

asked on

Dynamic Variable Names

Is it possible to take the values of two variables, and put them together to form a third variable name?
For instance, lets say I have the following variables:
(I am leaving off quotes to prevent problems with the form)

animalA = cat
animalB = dog
animalC = fish
animalD = bird
can I then add two values together to crreate a third variable name?

For instance, can I add animalA & animalC to create the variable named catfish, which according to the list below has a value of 12?

catfish = 12
birddog = 13
catdog = 14
Avatar of Mennovdh
Mennovdh

You can't do that in vbscript, unless I'm sorely mistaken, but in javascript you can;

function dothing(){
      var a='dog';
      var b='cat';
      eval('var '+a+b+'=\'I like puppies\';')
      alert(dogcat);
}

but I suppose you use vbscript for your asp, right?
How about this ?

animalA = "cat"
animalB = "dog"
animalC = "fish"
animalD = "bird"
CombinedAnimal = animalA & animalC
response.write "Valeu " & CombinedAnimal
CombinedAnimal=12
response.write "Vale " & CombinedAnimal
response.end
Avatar of nistmaru

ASKER

Yes, I use VBScript, but what about a mix of the two? Would it work if the list of variables was in a javascript include file?

I am using the file system object to return a list of all PDF files in a folder where the naming convention is the product part number. I then create a hyperlink to each pdf file, but rather than the file name being the hyperlink, I want touse a descriptive title.

Basically, I have a script that where each PDF file will have a corresponding title that resides with a list of all titles in an include file.

Lets call them abc.pdf and xyz.pdf. The titles will be in the include file like this:
ttl_abc = 'High Quality Machine Parts'
ttl_xyz = 'High Temp Materials'

For instance, when the file 'abc.pdf' is returned, it the script will check the list in the include file to see if there is a value for ttl_abc, and if there is, then it will create a hyperlink to the PDF file using the title as the link. If there was no value for ttl_abc, then it will create a link to the PDF using the PDF filename as the link.



You can use session object for this.

animalA = "cat"
animalB = "dog"
animalC = "fish"
animalD = bird

session(animalA & animalC) = 12

now you can do...
Response.Write session("catfish")
Using the session object will work, but I will have dozens, if not hundreds of files, won't that eat up system resources?
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Amend this line
response.write "<a href=" & x.name & ">" & "ttl_" & temp(0) & "</a><br>"

to

response.write "<a href=" & x.name & ">" & eval("ttl_" & temp(0)) & "</a><br>"
This worked perfectly, thank you very much!!