Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request.QueryString and Split Function

Status
Not open for further replies.

qberta01

Programmer
Nov 14, 2005
113
Hello!

I would like to take my query string:

ASPPage2.asp?Report=Test.rpt&begin=12/1/2006&end=12/31/2006

and somehow loop through it in a way that I get the name and the value pair. For example, the first time through I get:

Dim parameter
Dim paramvalue

Parameter = Report
Paramvalue = Test.rpt

Loop to next one…

Parameter = begin
Paramvalue = 12/1/2006

…..etc….

What I am trying to do is break up the query string and send the values to the parameters in a crystal report. I want to be able to use one asp for all reports and make the parameters dynamic without the need to type out each and every possible parameter. I know this forum is not about Crystal reports, but just wanted to explain why I want to do this. I am not sure that, once split, it will even work because Crystal is a bit fussy.

Anyway, if this is doable please help me out. Oh and if this seems more like a javascript thing let me know and accept my apologies for posting here.

Much appreciated….

Q

 
Definitely an asp thing, I know it's been discussed many times before but here's a quick example to get you started:
Code:
i=0
For Each param in Request.Querystring
   params(i) = param
   paramvals(i) = Request.Querystring(param)
   i = i+1
Next
Soemthing like that may be what you're looking for. You may need to Dim the arrays beforehand but what that particular snippet will do is put the name of the parameter into params(i) and its corresponding value into paramvals(i). Hope that helps.
 
Hello,

Yes it has been discussed many times before and I apologize for not researching it more throughly before submitting the post.

I was able to combine several bits of borrowed code (mostly from damber - so I do want to give damber credit for an excellent piece of code):

I basically used dambers code, but added
skeyWord = request.QueryString.Key(i+1).

I then wanted to remove the report name since I only want to collect the parameters being passed to Crystal. Then I loop through the dictionary to set the variables that are passed as parameters to the report.

dim sStr
sStr = request.QueryString
dim aParams : aParams = split(sStr, "&")
dim aKeyValue, i, sIDX
dim iIntMax : iIntMax = 5
dim sKeyword, sParam
dim dList : set dList = Server.CreateObject("Scripting.Dictionary")
Dim Keys, Items

'/// Collect the Values wanted into the dictionary object
for i= lbound(aParams) to ubound(aParams)
aKeyValue = split(aParams(i),"=")
skeyWord = request.QueryString.Key(i+1)
sIDX = skeyWord
sParam = aKeyValue(ubound(aKeyValue))
dList.add sIDX, aKeyValue(ubound(aKeyValue))
next

dList.Remove("Report")

'Get dictionary Keys
Keys = Dlist.Keys

'Get dictionary Items
Items = DList.Items

'Loop through Keys array
For iCount = 0 To UBound(Keys)
param=Keys(iCount)
crystalparam=Items(iCount)
Session("oRpt").ParameterFields.GetItemByName(param).AddCurrentValue(crystalparam)
Next

'/// Clean up
set dList = nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top