Solved

Dynamic Variable Names

Posted on 2003-10-28
9
2,329 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:nistmaru
9 Comments
 
LVL 2

Expert Comment

by:Mennovdh
Comment Utility
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?
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
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
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
0
 

Author Comment

by:nistmaru
Comment Utility
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.



0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 14

Expert Comment

by:puranik_p
Comment Utility
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")
0
 

Author Comment

by:nistmaru
Comment Utility
Using the session object will work, but I will have dozens, if not hundreds of files, won't that eat up system resources?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
Why dynamic variables?
You have a list of files and their titles like this?
<%
ttl_abc = 'High Quality Machine Parts'
ttl_xyz = 'High Temp Materials'
%>

You use FSO to get a list of all the files in a directory.  So it should be a simple case, as in your example, of....
<%
   ttl_abc = 'High Quality Machine Parts'
   ttl_xyz = 'High Temp Materials'
   ... etc for all the descriptive titles

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(folderspec)
   Set fc = f.Files
   For Each x in fc
        temp=split(x.name,".")
        response.write "<a href=" & x.name & ">" & "ttl_" & temp(0) & "</a><br>"
   Next
   Set fso=nothing
%>
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
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>"
0
 

Author Comment

by:nistmaru
Comment Utility
This worked perfectly, thank you very much!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now