"Bob Lehmann" wrote in message news:eY**************@TK2MSFTNGP10.phx.gbl...
: heh - Right, MS documentation is well known for its tight, efficient
coding
: examples.
Did I say that? I show you an example from the docs, which is what my post
followed, and now I'm making claims that MSFT docs examples are tight and
efficient coding? Is there a reason for this hostility?
: I suppose, then, that you would also reccommend this beauty taken from
MSDN
: Library...
<!--SNiP-->
Now you're just being ridiculous and off topic.
If you want to be specific and efficient, then your response should be
relative to what was asked. If you just want to be ridiculous and off
topic, we can do that too.
You're right. It IS untested and plugged into the OPs code would not work.
You'd get an object error.
Dim MyMsg
Set MyMsg = server.createObject("Scripting.Dictionary")
MyMsg.Add "KeyVal1", "My Message1"
MyMsg.Add "KeyVal2", "My Message2"
MyMsg.Add "KeyVal3", "My Message3"
For Each k In MyMessage.Keys
Response.Write MyMessage(k) & "<br>"
Next
MyMessage is NOT a defined object.
It should actually be this:
Dim MyMsg, k
Set MyMsg = CreateObject("Scripting.Dictionary")
MyMsg.Add "KeyVal1", "My Message1"
MyMsg.Add "KeyVal2", "My Message2"
MyMsg.Add "KeyVal3", "My Message3"
For Each k In MyMsg.Keys
Response.Write MyMsg(k) & "<br />"
Next
For someone who is crying for efficiency, one would think you'd test before
responding or at least use the same object especially when you're whining
over one line of code.
But, if we really wanted to be efficient, we'd make these all purpose
routines so they could be used again, wouldn't we? And, we'd probably
#include them but I'll leave that as an exercise.
Dim MyMsg, MyNextMsg
Set MyMsg = CreateObject("Scripting.Dictionary")
Set MyNextMsg = CreateObject("Scripting.Dictionary")
strMyMsg = "KeyVal1,My Message1,KeyVal2,My Message2,KeyVal3,My Message3"
strMyMsg2 = "KeyVal4,My Message4,KeyVal5,My Message5,KeyVal6,My Message6"
strMyNextMsg = "KeyVal1,Obladi,KeyVal2,Oblada,KeyVal3,Life goes on bra"
sub addItems(d, str)
dim m, i
m = split(str,",")
for i = 0 to ubound(m) step 2
d.Add m(i), m(i + 1)
next
end sub
sub showItems(d)
dim k
For Each k In d.Keys
Response.Write d(k) & "<br />"
Next
end sub
addItems MyMsg, strMyMsg
addItems MyMsg, strMyMsg2
showItems MyMsg
addItems MyNextMsg, strMyNextMsg
showItems MyNextMsg
set MyMsg = nothing
set MyNextMsg = nothing
or this...
Dim MyMsg, MyNextMsg
Set MyMsg = CreateObject("Scripting.Dictionary")
Set MyNextMsg = CreateObject("Scripting.Dictionary")
strMyMsg = Array("KeyVal1","My Message1","KeyVal2","My
Message2","KeyVal3","My Message3")
strMyMsg2 = Array("KeyVal4","My Message4","KeyVal5","My
Message5","KeyVal6","My Message6")
strMyNextMsg = Array("KeyVal1","Obladi","KeyVal2","Oblada","KeyVa l3","Life
goes on bra")
sub addItems(d, m)
dim i
for i = 0 to ubound(m) step 2
d.Add m(i), m(i + 1)
next
end sub
sub showItems(d)
dim k
For Each k In d.Keys
Response.Write d(k) & "<br />"
Next
end sub
addItems MyMsg, strMyMsg
addItems MyMsg, strMyMsg2
showItems MyMsg
addItems MyNextMsg, strMyNextMsg
showItems MyNextMsg
And if you change:
Response.Write d(k) & "<br />"
To:
WScript.Echo d(k)
It works in WSH.
It still may not be the most efficient but it's more modular and reusable.
If you're going to have a cow about efficiency, then please use the same
object the OP posted otherwise it just looks like misplaced anger.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library -
http://msdn.microsoft.com/library/default.asp