Skip to content

felipe-gustavo/QueryStringParameters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

QueryStringParameters

Work with Query String Parameters in VBA easily

Dependencies

Microsoft Scripting Runtime

How to use

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

Importing a query string to object

Dim objQueryStr as QueryStringParameters

Set objQueryStr = New QueryStringParameters

objQueryStr.parseQueryStringParameters "foo[bar]=value1&foo[menu]=value2"

The below examples has based in above command

Getting value in string

Debug.Print objQueryStr.toString()
' >output: foo[bar]=value1&foo[menu]=value2

Adding new field in query string

objQueryStr.add "myValue", Array("foo", "top")

Debug.Print objQueryStr.toString()
' >output: foo[bar]=value1&foo[menu]=value2&foo[top]=myValue

Adding new field in query string as first field

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

Adding new field in query string after a field

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

Adding new sequential field

Set objQueryStr = New QueryStringParameters

objQueryStr.add "value1", Array("foo", "")
objQueryStr.add "value2", Array("foo", "")

Debug.Print objQueryStr.toString()
' >output: foo[]=value1&foo[]=value2

Adding new value after sequential field

objQueryStr.add "newValue", Array("foo", "new"), .getSequentialKeyByIndex(0, array("foo"))

Debug.Print objQueryStr.toString()
' >output: foo[]=value1&foo[new]=newValue&foo[]=value2

Removing fields

objQueryStr.remove Array("foo", "new")
objQueryStr.remove Array("foo", .getSequentialKeyByIndex(0, array("foo")))

Debug.Print objQueryStr.toString()
' >output: foo[]=value1

Updating fields

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

Getting value

Dim objDictionary as Dictionary
Set objDictionary = objQueryStr.getValue Array("foo")

For Each Item in objDictionary
  Debug.Print Item
Next
' >output: 1
' >output: 2

Getting value nonexistent

value = objQueryStr.getValue Array("foo", "new")

Debug.Print IsError(Value)
' >output: True