preload

AssociateParameters (QTP, TestComplete, VBScript)

Posted by Albert Gareev on Jan 02, 2009 | Categories: Associative ArraySource code

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


  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.