473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using Eval to set dynamic object names

I've ran into a little trouble with Eval, hoping someone can point it
out to me

This code works :

var_ktml = "textarea2"
Set ktml_textarea2 = new ktml4
Eval("ktml_" & var_ktml).Init var_ktml

This code doesn't :

var_ktml = "textarea2"
Set Eval("ktml_" & var_ktml) = new ktml4
Eval("ktml_" & var_ktml).Init var_ktml
Can anyone point out the error of my ways ?

Cheers,
Mark

Jul 13 '06 #1
2 2066

<we*****@gt4web.co.ukwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
I've ran into a little trouble with Eval, hoping someone can point it
out to me

This code works :

var_ktml = "textarea2"
Set ktml_textarea2 = new ktml4
Eval("ktml_" & var_ktml).Init var_ktml

This code doesn't :

var_ktml = "textarea2"
Set Eval("ktml_" & var_ktml) = new ktml4
Eval("ktml_" & var_ktml).Init var_ktml
Can anyone point out the error of my ways ?
Simple, stop using Eval.

Use an array or even Scripting.Dictionary to collect and lookup objects

Cheers,
Mark

Jul 13 '06 #2
we*****@gt4web.co.uk wrote:
I've ran into a little trouble with Eval, hoping someone can point it
out to me

This code works :

var_ktml = "textarea2"
Set ktml_textarea2 = new ktml4
Eval("ktml_" & var_ktml).Init var_ktml

This code doesn't :

var_ktml = "textarea2"
Set Eval("ktml_" & var_ktml) = new ktml4
Eval("ktml_" & var_ktml).Init var_ktml
Can anyone point out the error of my ways ?
Sure. You see that line that starts with "Eval ... "? That's the problem
right there*.
Try this instead:

dim var_ktml,ktml_objs, ktml_obj
set ktml_objs = createobject("scripting.dictionary")
var_ktml = "textarea2"
Set ktml_obj = new ktml4
ktml_objs.Item("ktml_" & var_ktml) = ktml_obj
When you want to use the object:

Set ktml_obj = ktml_objs.Item("ktml_" & var_ktml)
ktml_obj.Init var_ktml
ktml_objs.Item("ktml_" & var_ktml) = ktml_obj

Bob Barrows
* http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Oleg Alistratov | last post by:
Is in javascript a method to get object's identifier as string? E.g., may I write function GetName thus, that var v; var s = GetName(v); has led to s == "v"
6
by: amohajer | last post by:
what does eval function do in javascript language and what are its usages?
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
21
by: hemant.singh | last post by:
Hello all, I am try'g to send window.location.href to the server script who will generate dynamic javascript according to the referral name comg in as param Now bcz <script language="javascript"...
2
by: radykl | last post by:
Can anyone explain me why you need to add open and close parenthesis to a JSON text in order to use eval() to parse it? For example: var json = "{a: 'abc', b: 'def'}"; var obj1 = eval("(" +...
34
by: davehowey | last post by:
I have a problem. I'm writing a simulation program with a number of mechanical components represented as objects. When I create instances of objects, I need to reference (link) each object to the...
8
by: abhishek | last post by:
>>a,b=3,4 7 Now I want to evaluate y by substituting for the evaluated value of x. eval(y) will try to add "a+b" to 3 and return an error. I could do this, 10 but this becomes unwieldy if I...
0
by: Lie Ryan | last post by:
On Tue, 30 Sep 2008 16:04:34 -0500, William Purcell wrote: when you pass mydict, it is used as the global variables in the eval, right? Then, you passed a code to eval('...', mydict), sometimes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.