前面我們已經了解如何取得使用者上傳的參數值,但那是在已經知道參數名稱的狀況之下才可以;而使用QueryString 屬性我們可以只利用索引來取得參數值,QueryString 屬性的型別是NameValueCollection。下面的程序中我們先定義一個NameValueCollection 型態變量來接收QueryString 的內容,然后使用一組巢狀循環來取得參數名稱及內容:
<Html>
<Script Language="VB" Runat="Server">
Sub Page_Load(Sender As Object,e As Eventargs)
Dim shtLoop1, shtLoop2 As Short
Dim arA(), arB() As String
Dim colA As NameValueCollection
colA=Request.QueryString
arA = colA.AllKeys ' 取得全部的鍵值并存到一個數組中
For shtLoop1 = 0 To UBound(arA)
Response.Write("參數名:" & arA(shtLoop1))
arB = colA.GetValues(shtLoop1) ' 利用外循環的索引來取得參數內容并
存到一個數組中
For shtLoop2 = 0 To UBound(arB)
Response.Write(" 內容:" & arB(shtLoop2) & "<br>")
Next shtLoop2
Next shtLoop1
End Sub
</Script>
</Html>