Solved

Declaring a dynamic variable in a Vbscript

Posted on 2002-04-12
3
407 Views
Last Modified: 2008-03-03
I there a way in vbscript to declare a dynamic variable?

For example:

 Myvariable & i= "Some Text"

 I know you can do it in JavaScript by using a
build in function called Eval,
Eval(Myvariable + i)= "Some Text";
0
Comment
Question by:7of9121098
  • 2
3 Comments
 
LVL 33

Expert Comment

by:knightEknight
Comment Utility
you can use javascript together with vbscript to do this:


<HTML>
<HEAD>

<SCRIPT language='javascript'>

 eval("var variable" + 1 + " = 'a'");
 eval("var variable" + 2 + " = 'b'");
 eval("var variable" + 3 + " = 'c'");

 alert(variable1);
 alert(variable2);
 alert(variable3);

 function jsEval(jscode)
 {
   return(eval(jscode));
 }

</script>

<SCRIPT language='vbscript'>

 msgbox(variable1)
 msgbox(variable2)
 msgbox(variable3)

 dim v4
 jsEval("v4 = 'd'")
 msgbox(v4)

</script>

</head>

<BODY>
</body>
</html>
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 50 total points
Comment Utility
will also work with server-side code in ASP:


<SCRIPT language='javascript' runat='server'>
 function jsEval(jscode)
 {
   return(eval(jscode));
 }
</script>


<%
 dim v4
 jsEval("v4 = 'd'")
 response.write v4
%>
0
 

Author Comment

by:7of9121098
Comment Utility
Excellent...
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

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 …
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/…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

11 Experts available now in Live!

Get 1:1 Help Now