AssociateParameters (QTP, TestComplete, VBScript)
Parent page: Service Functions – Dictionary (QTP, TestComplete, VBScript)
Description
Converts a string of comma-separated pairs “a=1, b=2, c = 3” to a Dictionary object. Spaces will be trimmed. Special characters: “=” “,” – can be escaped with backslash.
Replace special characters in the string – associate pairs – replace characters back.
Implementation
Public Function AssociateParameters(ByVal strParams)
Dim objDictionary, Values, strPair, Pair
Dim intCount, i
strParams = Replace(strParams, "\,", Chr(176))
strParams = Replace(strParams, "\=", Chr(187))
Values = Split(strParams, ",")
intCount = UBound(Values)
Set objDictionary = CreateObject("Scripting.Dictionary")
For i=0 To intCount
strPair = Trim(Values(i))
Pair = Split(strPair, "=")
If UBound(Pair) = 1 Then
If Not objDictionary.Exists(Trim(Pair(0))) Then
objDictionary.Add Trim(Pair(0)), Replace(Replace(Trim(Pair(1)), Chr(176), ","), Chr(187), "=")
Else
objDictionary.Item(Trim(Pair(0))) = Replace(Replace(Trim(Pair(1)), Chr(176), ","), Chr(187), "=")
End If
End If
Next
Set AssociateParameters = objDictionary
End Function

