By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 2,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Using Eval to set dynamic object names

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

<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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.