I am running into a bit of a problem with ByVal in VBScript. Here’s a quick sample script that I wrote to illustrate the issue:
<%
Option Explicit
dim PublicDict
Set PublicDict = createobject("Scripting.Dictionary")
PublicDict.Add "MyKey", "What's up doc?"
response.write OutputStringFromDictionary( PublicDict ) & "<br />"
response.write PublicDict("MyKey")
Set PublicDict = nothing
Function OutputStringFromDictionary( ByVal DictionaryParameter )
DictionaryParameter("MyKey") = replace(DictionaryParameter("MyKey"), "'", "''")
OutputStringFromDictionary = DictionaryParameter("MyKey")
end Function
%>
This script outputs these lines to the browser:
What”s up doc?
What”s up doc?
I was hoping to get:
What”s up doc?
What’s up doc?
How do I make it so that OutputStringFromDictionary doesn’t modify the original dictionary?
You’d have to clone the actual data somehow. Passing the dictionary by value prevents the dictionary itself from being modified, but you still have pointers to the same items that the dictionary references. You can’t modify the dictionary, but you can modify the items it contains.