How to use Dynamic Arrays

Results 1 to 2 of 2

Thread: How to use Dynamic Arrays

  1. #1
    Steve Rowson Guest

    Default How to use Dynamic Arrays

    I want a user to be able to select a part number and add it to his order. Then go back to the same page select a part number and add it to his order etc.<BR>So I need to store the PartID and the Quantity in an array.<BR>I have created an array, passed the values into it and I can read it okay. I then set a session variable equal to the array. But when I return to the page and add the next part, it is replacing the original data, not creating a new row in the array.<BR>The code is below.<BR>&#060;%@ LANGUAGE="VBScript" %&#062;<BR>&#060;%ReDim arrayParts(1,2)<BR>IntIndex = 0<BR>Session("IntIndex") = IntIndex<BR>arrayParts(0,Session("IntIndex")) = Session("PartsID")<BR>arrayParts(1,Session("IntInd ex")) = Session("Quantity")<BR>IntIndex = Session("IntIndex")+1<BR>ReDim Preserve arrayParts(1,IntIndex-1)<BR>Session("AllParts") = arrayParts%&#062;<BR>&#060;html&#062;<BR><BR>&#060 ;head&#062;<BR>&#060;title&#062;Add Part&#060;/title&#062;<BR>&#060;/head&#062;<BR><BR>&#060;body&#062;<BR>&#039this displays the data ok<BR>&#060;%For i = 0 to Ubound(arrayParts,2)<BR>Response.Write arrayParts(0,i)<BR>Response.Write arrayParts(1,i)<BR>Next%&#062;<BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    66

    Default RE: How to use Dynamic Arrays

    my guess would be as follows<BR> in these 2 lines :<BR><BR>IntIndex = 0<BR>Session("IntIndex") = IntIndex<BR>u r destroying all your work, no matter what u did<BR>I would do it like this<BR>if isempty (Session("IntIndex")) then<BR> IntIndex = 0 <BR>else<BR> IntIndex = Session("IntIndex")<BR>end if<BR><BR>therefore this line:<BR><BR>IntIndex = Session("IntIndex")+1<BR><BR>should be replaced by:<BR><BR>Session("IntIndex") = Session("IntIndex")+1

Posting Permissions

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