Solved

Dynamic Variable Names

Posted on 2003-10-28
9
2,331 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
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
 
LVL 58

Expert Comment

by:Gary
ID: 9634179
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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 500 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to hide hide popup page refresh second time? 10 124
ASP CDO - Limiting Connections 2 50
Error in query expression 3 42
jquery to restrict certain words from input in form 11 34
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 a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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