Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Lincoln (UK)
    Posts
    138
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Unhappy array looping problem

    I have a silly issue which I hope someone can help me with.

    Taking a simple array, I need to loop though and process a simple string of words.
    This is what I'm attempting:
    Code:
    <%
    If Request.Form("dirty") <> "" Then
    	dim strArray, processString
    	processString = Request.Form("dirty")
    	strArray = Split(processString," ")
    	For i=o to ubound(strArray)
    		set Search = new ClassItem
    			If processedString <> "" Then processedString = processedString & " "
    			processedString = processedString & Search.Class(strArray(i))
    		set Search = nothing
    	Next
    	Response.Write "<strong>Original String: </strong>" & processString & vbcrlf & "<hr />" & vbcrlf
    	Response.Write "<strong>Output String: </strong>" & processedString & "<br />&nbsp;"
    End If
    %>
    However, it only seems to process the first item in the array (and yes, if I print the array it's all there).

    For example, this works fine:
    Code:
    <%
    If Request.Form("dirty") <> "" Then
    	dim strArray, processString
    	processString = Request.Form("dirty")
    	strArray = Split(processString," ")
    		set Search = new ClassItem
    			If processedString <> "" Then processedString = processedString & " "
    			processedString = processedString & Search.Class(strArray(0))
    		set Search = nothing
    		set Search = new ClassItem
    			If processedString <> "" Then processedString = processedString & " "
    			processedString = processedString & Search.Class(strArray(1))
    		set Search = nothing
    		set Search = new ClassItem
    			If processedString <> "" Then processedString = processedString & " "
    			processedString = processedString & Search.Class(strArray(2))
    		set Search = nothing
    	Response.Write "<strong>Original String: </strong>" & processString & vbcrlf & "<hr />" & vbcrlf
    	Response.Write "<strong>Output String: </strong>" & processedString & "<br />&nbsp;"
    End If
    %>
    Any ideas why can't I loop though the array?
    (BTW, if I remove the class and run it as a standalone function, I get the same result.

    Any help, much appreciated.

    Justin
    Last edited by Keltoi; 09-16-2009 at 04:59 PM. Reason: Resolved as noted in reply

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Lincoln (UK)
    Posts
    138
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Sorted, changed the 'i=o' to 'j=o' and looping fine...
    Code:
    	For j=o to ubound(strArray)
    		set Search = new ClassItem
    			If processedString <> "" Then processedString = processedString & " "
    			processedString = processedString & Search.Class(strArray(j))
    		set Search = nothing
    	Next
    Last edited by Keltoi; 09-16-2009 at 04:57 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •