Manually parse query string values in VB6

Dim url As String
Dim queryString As String
Dim sQueryStringValues() As String
Dim sIndustrySectorId As String
Dim sSiteId As String
Dim sMode As String

'1. url is normal
'2. url is empty
'3. SiteID is missing

url = "http://localhost/Posting/templates/SiteXsl.asp?IndustryID=0&SiteID=4&Mode=4"
'url = ""
'url = "http://localhost/Posting/templates/SiteXsl.asp?IndustryID=0&Mode=4"

If InStr(1, url, "?", vbTextCompare) Then
    queryString = Split(url, "?")(1)

    If InStr(1, queryString, "&", vbTextCompare) Then
        sQueryStringValues = Split(queryString, "&")

        Dim str As Variant
        For Each str In sQueryStringValues
            If InStr(1, str, "SiteID=", vbTextCompare) Then
                sSiteId = Replace(str, "SiteID=", "")
            ElseIf InStr(1, str, "IndustryID=", vbTextCompare) Then
                sIndustrySectorId = Replace(str, "IndustryID=", "")
            ElseIf InStr(1, str, "Mode=", vbTextCompare) Then
                sMode = Replace(str, "Mode=", "")
            End If
        Next

        MsgBox "IndustrySectorID: " & sIndustrySectorId
        MsgBox "SiteID: " & sSiteId
        MsgBox "Mode: " & sMode
    End If
End If
Manually parse query string values in VB6

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s