Connecting Tech Pros Worldwide Forums | Help | Site Map

Back on itself

Newbie
 
Join Date: Aug 2008
Posts: 1
#1: Aug 20 '08
Hi
I have a pop up form that references a query string from a previous page successfully.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim rs_test
  3. Dim rs_test_cmd
  4. Dim rs_test_numRows
  5.  
  6. Set rs_test_cmd = Server.CreateObject ("ADODB.Command")
  7. rs_test_cmd.ActiveConnection = MM_conn_Sidecounter_STRING
  8. rs_test_cmd.CommandText = "SELECT * FROM tblSchoolPrograms WHERE DataCollect2ID=" & request.QueryString("count")& "" 
  9. rs_test_cmd.Prepared = true
  10.  
  11. Set rs_test = rs_test_cmd.Execute
  12. rs_test_numRows = 0
  13. %>
It uses this number to populate 2 text fields in a form successfully. I the have a submit button on the form that calculates a word count. (free code from the web I have adjusted)

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim strScriptName
  3. Dim strInputText
  4. Dim strInputText2
  5.  
  6. ' Read in the script name so I know where to
  7. ' point the form's action to.
  8. strScriptName = Request.ServerVariables("URL")
  9.  
  10. ' Read in the input from the text area.
  11. strInputText = Request.Form("txtWordCount")
  12. strInputText2 = Request.Form("txtWordCount2")
  13.  
  14. ' Check for empty input and ignore it...
  15. If strInputText = "" Then
  16.     strInputText = ""
  17. Else
  18.     ' Echo out the input:
  19.     'Response.Write "You entered:<br />" & vbCrLf
  20.     'Response.Write "<pre>"
  21.     'Response.Write Server.HTMLEncode(strInputText)
  22.     'Response.Write "</pre>" & vbCrLf
  23.  
  24.     ' Print out the counts we got:
  25.     Response.Write "<p>The word count for Project Descriptions is <b>" _
  26.         & GetWordCount(strInputText) _
  27.         & "</b> words and <b>" _
  28.         & GetCharCount(strInputText) _
  29.         & "</b> characters.</p><br />" & vbCrLf
  30. End If
  31.  
  32. If strInputText2 = "" Then
  33.     strInputText2 = ""
  34. Else
  35.     ' Echo out the input:
  36.     'Response.Write "You entered2:<br />" & vbCrLf
  37.     'Response.Write "<pre>"
  38.     'Response.Write Server.HTMLEncode(strInputText)
  39.     'Response.Write "</pre>" & vbCrLf
  40.  
  41.     ' Print out the counts we got:
  42.     Response.Write "<p>The word count for Project Outcomes is <b>" _
  43.         & GetWordCount(strInputText2) _
  44.         & "</b> words and <b>" _
  45.         & GetCharCount(strInputText2) _
  46.         & "</b> characters.</p><br />" & vbCrLf
  47. End If
  48.  
  49. ' I wrapped these into functions so you can reuse them.
  50. '**** Begin Functions ***********************************
  51. Function GetWordCount(strInput)
  52.     Dim strTemp
  53.  
  54.     ' Deal with tabs and carriage returns
  55.     ' by replacing them with spaces.
  56.     strTemp = Replace(strInput, vbTab, " ")
  57.     strTemp = Replace(strTemp, vbCr, " ")
  58.     strTemp = Replace(strTemp, vbLf, " ")
  59.  
  60.     ' Remove leading and trailing spaces
  61.     strTemp = Trim(strTemp)
  62.  
  63.     ' Combine multiple spaces down to single ones
  64.     Do While InStr(1, strTemp, "  ", 1) <> 0
  65.         strTemp = Replace(strTemp, "  ", " ")
  66.     Loop
  67.  
  68.     ' Get a count by splitting the string into an array
  69.     ' and retreiving the number of elements in it.
  70.     ' I add one to deal with the 0 lower bound.
  71.     GetWordCount = UBound(Split(strTemp, " ", -1, 1)) + 1
  72. End Function ' GetWordCount
  73.  
  74. Function GetCharCount(strInput)
  75.     GetCharCount = Len(strInput)
  76. End Function ' GetCharCount
  77. '**** End Functions *************************************
  78. ' Here's our form that we fill with the value they
  79. ' entered last time.
  80. %>
  81.  
The problem is as a static page it all works perfectly and counts successfully. But when done dynamically it obviously can't reference itself to repopulate the query string.

I have tried to adjust the strscriptname with

strcollectpage = request.QueryString(rs_collect)
strpathRoute = request.ServerVariables("URL")
strScriptName = strpathRoute & "?count=" & strcollectpage

My coding is not that good and I have reached a stalemate, errors galore.
Any help would be great
Cheers
Peter

DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#2: Aug 21 '08

re: Back on itself


Hi Peter,

I'm a little bit confused about what it is you're trying to do. Are you trying redirect the page to another page while populating the querystring?

If so you can use Response.Redirect like this:
Expand|Select|Wrap|Line Numbers
  1. strcollectpage = request.QueryString(rs_collect)
  2. strpathRoute = request.ServerVariables("URL")
  3. strScriptName = strpathRoute & "?count=" & strcollectpage
  4. Response.Redirect strScriptName
Does that help? If not can you clarify your problem for me please.

Dr B
Reply