Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a VBScript function return a dictionary?

I have a dictionary of form data that I want to modify using a function.

function queryCleanForm(myDictForm)

    dim arrayKeys
    arrayKeys = myDictForm.keys

    for i=0 to myDictForm.count-1
        myDictForm(arrayKeys(i)) = replace(myDictForm(arrayKeys(i)), "'", "''")
        response.write myDictForm(arrayKeys(i))
    next

    queryCleanForm = myDictForm
end function

The problem is the line queryCleanForm = myDictForm errors as

Wrong number of arguments or invalid property assignment 

Is there a way to do this in VBScript?

like image 376
quakkels Avatar asked Oct 27 '10 21:10

quakkels


People also ask

What is a dictionary in VBScript?

VBScript Dictionary Objects. A Dictionary object can be compared to a PERL associative array. Any Values can be stored in the array and each item is associated with a unique key. The key is used to retrieve an individual element and it is usually an integer or a string, but can be anything except an array.

What is the Dictionary object used for?

The Dictionary object is used to hold a set of data values in the form of (key, item) pairs. A dictionary is sometimes called an associative array because it associates a key with an item.

What is the VBScript key used for?

The key is used to retrieve an individual element and it is usually an integer or a string, but can be anything except an array. VBScript classes are enclosed within Class .... End Class. <!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim obj_datadict ' Create a variable.

How do I retrieve the item value for a dictionary key?

To retrieve the item value for a given key, use the .Item property. This is the default property for a Dictionary object. For example: The Rhino.Print statement displays the item value stored in the dictionary for the "Salami" key.


2 Answers

Try this:

SET queryCleanForm = myDictForm

With objects you need to use SET to tell VBScript that it is an object reference you are assigning not a value type.

like image 171
JohnFx Avatar answered Oct 03 '22 02:10

JohnFx


Yes, you need to use the SET command:

Set queryCleanForm = myDictForm

like image 28
Anzoid Avatar answered Oct 03 '22 01:10

Anzoid