preload

AssociateRecords (QTP, TestComplete, VBScript)

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

Parent page: Service Functions – Dictionary (QTP, TestComplete, VBScript)

Description

Converts a string of comma-separated sets of parameters. Example: “User1 {login=john_doe, password=john1}, User2 {login=jane_doe, password=jane1}”

Implementation

Public Function AssociateRecords(ByVal strRecordSet)
	Dim objDictionary
	Dim intScan, intCount, sLine, sRecordName, sRecordData

	Set objDictionary = CreateObject("Scripting.Dictionary")
	sLine = strRecordSet
	intCount = 0

	Do
		intScan = InStr(1, sLine, "{")

		If Not (intScan > 0) Then
			Set AssociateRecords = objDictionary
			Exit Function
		End If

		sRecordName = Trim(Replace(Left(sLine, intScan-1), ",", " "))
		If sRecordName = "" Then
			sRecordName = "Noname" & intCount
		End If

		sLine = Mid(sLine, intScan+1)

		intScan = InStr(1, sLine, "}")

		If Not (intScan > 0) Then
			Set AssociateRecords = objDictionary
			Exit Function
		End If

		sRecordData = Left(sLine, intScan-1)
		If Not objDictionary.Exists(sRecordName) Then
			objDictionary.Add sRecordName, AssociateParameters(sRecordData)
		Else
			Set objDictionary.Item(sRecordName) = AssociateParameters(sRecordData)
		End If

		intCount = intCount +1
		sLine = Mid(sLine, intScan+1)
	Loop While TRUE

	Set AssociateRecords = 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.