Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamic Variable Names

Posted on 2003-10-28
9
Medium Priority
?
2,339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 2

Expert Comment

by:Mennovdh
ID: 9634080
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
ID: 9634162
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:nistmaru
ID: 9634212
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
 
LVL 14

Expert Comment

by:puranik_p
ID: 9634216
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
ID: 9634300
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 2000 total points
ID: 9634304
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
ID: 9634393
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
ID: 9634903
This worked perfectly, thank you very much!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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