Work with Query String Parameters in VBA easily
Microsoft Scripting Runtime
After import the file (download here) to your VBA project, let's go to the examples.
Create a Object:
Dim objQueryStr as QueryStringParameters Set objQueryStr = New QueryStringParameters
Dim objQueryStr as QueryStringParameters Set objQueryStr = New QueryStringParameters objQueryStr.parseQueryStringParameters "foo[bar]=value1&foo[menu]=value2"
The below examples has based in above command
Debug.Print objQueryStr.toString() ' >output: foo[bar]=value1&foo[menu]=value2
objQueryStr.add "myValue", Array("foo", "top") Debug.Print objQueryStr.toString() ' >output: foo[bar]=value1&foo[menu]=value2&foo[top]=myValue
objQueryStr.add "mySecondValue", Array("foo", "bottom"), objQueryStr.addAsFirstValue Debug.Print objQueryStr.toString() ' >output: foo[bottom]=mySecondValue&foo[bar]=value1&foo[menu]=value2&foo[top]=myValue
objQueryStr.add "mySecondValue2", Array("foo", "bottom2"), "bottom" Debug.Print objQueryStr.toString() ' >output: foo[bottom]=mySecondValue&foo[bottom2]=mySecondValue2&foo[bar]=value1&foo[menu]=value2&foo[top]=myValue
Note: If the field doesn't exist, the new value will be inserted in last field
Set objQueryStr = New QueryStringParameters objQueryStr.add "value1", Array("foo", "") objQueryStr.add "value2", Array("foo", "") Debug.Print objQueryStr.toString() ' >output: foo[]=value1&foo[]=value2
objQueryStr.add "newValue", Array("foo", "new"), .getSequentialKeyByIndex(0, array("foo")) Debug.Print objQueryStr.toString() ' >output: foo[]=value1&foo[new]=newValue&foo[]=value2
objQueryStr.remove Array("foo", "new") objQueryStr.remove Array("foo", .getSequentialKeyByIndex(0, array("foo"))) Debug.Print objQueryStr.toString() ' >output: foo[]=value1
objQueryStr.update 2, Array("foo", "menu") '' Auto add objQueryStr.update 1, Array("foo", .getSequentialKeyByIndex(0, array("foo"))) '' Update sequential key Debug.Print objQueryStr.toString() ' >output: foo[]=1&foo[menu]=2
Dim objDictionary as Dictionary Set objDictionary = objQueryStr.getValue Array("foo") For Each Item in objDictionary Debug.Print Item Next ' >output: 1 ' >output: 2
value = objQueryStr.getValue Array("foo", "new") Debug.Print IsError(Value) ' >output: True