Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamic Variable Names

Posted on 2003-10-28
9
Medium Priority
?
2,342 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
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.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

927 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