NEED HELP WITH VBSCRIPT LOOPing WITH ARRAY

Author Message
kcoburn

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 5/24/2011
  • Status: offline
NEED HELP WITH VBSCRIPT LOOPing WITH ARRAY Tuesday, May 24, 2011 9:50 AM (permalink)
0
My For Loop code only does the first record, I need for it to loop through each record which is compiled in an array.  Please help: 
 
 
Dim mystring, myarray
mystring = (Recordset1.Fields.Item("attach").Value)
myarray = Split(mystring, ", ")
For i = 0 to UBound (myarray)
For each item in myarray
  objFSO.CopyFile (strPath & "/" & myarray(i)), (strPath2 & recordid & "/" & myarray(i)), True
  Response.write(myarray(i)) & "<BR>"
  Next
Next
 
#1
    ehvbs

    • Total Posts : 3320
    • Scores: 110
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    Re:NEED HELP WITH VBSCRIPT LOOPing WITH ARRAY Wednesday, May 25, 2011 12:38 AM (permalink)
    0
    The double/nested loops in:
     For i = 0 to UBound (myarray)  
    For each item in myarray
    objFSO.CopyFile (strPath & "/" & myarray(i)), (strPath2 & recordid & "/" & myarray(i)), True
    Response.write(myarray(i)) & "<BR>"
    Next
    Next
    are wrong. As you use i in the .CopyFile, change your code to
     For i = 0 to UBound (myarray)  
    objFSO.CopyFile (strPath & "/" & myarray(i)), (strPath2 & recordid & "/" & myarray(i)), True
    Response.write(myarray(i)) & "<BR>"
    Next
    and see what happens.
    BTW: Given that variable names shoud make sense, what meaning do you want to express with "myarray"? What are the () in the "Response.write" line for?
     
    #2
      kcoburn

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 5/24/2011
      • Status: offline
      Re:NEED HELP WITH VBSCRIPT LOOPing WITH ARRAY Wednesday, May 25, 2011 1:19 AM (permalink)
      0
      Thanks for the quick response.
       
      The myarray variable is supposed to contain a all values for a the "attach" field in the recordset.   I was just using the Response.Write to help narrow down the issues in the code.  This line will be removed once I can get the code working.
      I change the code and it still is not working, it is only copying the first record.  It does not loop through each record.  
       
      I am just trying to execute a copyFile command on each attach field value in the recordset.  I am so lost, I have tried everything from Do to While.
      <message edited by kcoburn on Wednesday, May 25, 2011 1:22 AM>
       
      #3
        ehvbs

        • Total Posts : 3320
        • Scores: 110
        • Reward points : 0
        • Joined: 6/22/2005
        • Location: Germany
        • Status: offline
        Re:NEED HELP WITH VBSCRIPT LOOPing WITH ARRAY Wednesday, May 25, 2011 2:33 AM (permalink)
        0
        This
        >> aWords = Split( "one,two,three", "," ) 
        >> For i = 0 To UBound( aWords )
        >>     WScript.Echo aWords( i )
        >> Next
        >>
        one
        two
        three
        >>
        to prove that the loop 'works' if the array (aWords) contains elements. So your array does not contain all values for a the "attach" field in the recordset. Now if you had named your string "csvAllFilesToCopy" (meaning "comma separated list of the files to copy", it would be easy to see/ask "does one row of your recordset contain all files in the attach field?". Probably not.
        To deal with all rows of your recordset, you'll have to loop:
        Do Until recordset1.EOF 
        ... get the current value of the attach field and do the copy
        recordset1.MoveNext
        Loop
        (or something like that).
         
        #4
          kcoburn

          • Total Posts : 3
          • Scores: 0
          • Reward points : 0
          • Joined: 5/24/2011
          • Status: offline
          Re:NEED HELP WITH VBSCRIPT LOOPing WITH ARRAY Wednesday, May 25, 2011 3:21 AM (permalink)
          0
          Thanks a bunch, you are great! That worked perfect.
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9