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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping up with an array when moving back and forth between pages

Status
Not open for further replies.

spacehawk

Programmer
May 17, 2000
30
US
I am writing a function that involves three pages.&nbsp;&nbsp;Selections are made on the first.&nbsp;&nbsp;A 2D array is created on the second page and the first record is filled.<br><br>Then it moves back to the first page for another selection and back to the second page.&nbsp;&nbsp;A second record is created this time to add to the first one.<br><br>Eventually it goes to the third page where the array is printed.&nbsp;&nbsp;I need help on keeping the values in the array when moving from page to page.
 
You can use a session variable,&nbsp;&nbsp;but this type of technique doesn't scale well.&nbsp;&nbsp;If this is a high traffic site,&nbsp;&nbsp;you should strive to maintain statelessness as much as possible.<br><br>How much data are we talking about?<br><br><br> <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Dear spacehawk,<br><br>Nick is correct about being careful using the session object. There are many considerations and each new version of Windows and IIS are tuned even more to provide for the use of session objects.<br><br>If you really want to try it out and stress test it, depending on your server environment and load it might be just fine.<br><br>However I don't think you can store Arrays in session variables. Only text and ActiveX objects.<br><br>So you might want to look at creating your own ADODB.Recordset to store the data. As of MDAC 2.5 or 3.0 or whatever version it was you can generate your own recordset by defining columns and using AddNew() and setting the column values. You can find sample code for this at msdn.microsoft.com.<br><br>Another approach is to just put the values into the next page as hidden inputs, that way the next page gets them all. Something Like this:<br><br>//page one<br>&lt;form …&gt;<br>&lt;input type=&quot;text&quot; name=&quot;FirstName&quot;&gt;<br>&lt;/form&gt;<br><br>// page two<br>&lt;form …&gt;<br>&lt;input type=&quot;hidden&quot; name=&quot;FirstName&quot; value=&quot;&lt;%=Request(&quot;firstname&quot;)%&gt;&quot;&gt;<br>&lt;input type=&quot;text&quot; name=&quot;LastName&quot;&gt;<br>&lt;/form&gt;<br><br>//page three gets both variable in the request variable collection<br>You sent&lt;br&gt;<br>First Name: &lt;%=Request(&quot;firstName&quot;)%&gt;&lt;br&gt;<br>Last Name: &lt;%=Request(&quot;LastName&quot;)%&gt;<br><br>Hope this helps<br>-pete<br>
 
Pete,<br>&nbsp;&nbsp;&nbsp;You can store arrays in session variables, but can't change them directly.&nbsp;&nbsp;You need to add a level of indirection:<br><br>dim a(1)<br>dim b<br>a(0)=&quot;nick&quot;<br>a(1)=&quot;bulka&quot;<br>session(&quot;myarray&quot;) = a<br>b = session(&quot;myarray&quot;)<br>Response.Write b(1)<br><br>Not very intuitive, I agree, but it works. <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
After I submitted, I kept pounding at it and was able to use hidden inputs to keep up with it.&nbsp;&nbsp;I use&lt;input Type=&quot;hidden&quot; Name=&quot;ID&quot; value=&quot;&lt;%=ID%&gt;;&lt;%=Product%&gt;;&lt;%=Amount%&gt;&quot;&gt;<br><br>Then I use ID=Request.Form(&quot;ID&quot;)<br><br>Each time through the page, product and amount are added to the ID string.<br><br>I end up with a string like this:&nbsp;&nbsp;&nbsp;;10200;3;20010;4;10110;2<br><br>Is there a way I can count how many items are in this list?&nbsp;&nbsp;Can I count the semicolons?<br><br>I am almost there.&nbsp;&nbsp;Thanks.
 
request.form(&quot;id&quot;).count will do it. <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
When I used request.form(&quot;id&quot;).count, it returned a value of 1, but I figured out a different way to do it.&nbsp;&nbsp;I added a value of x to the end of the string on the last pass and used<br><br>Do While ID(i)&lt;&gt;&quot;x&quot;<br><br><br>Loop<br><br>Probably not the most efficient way, but it did work.
 
Dear hawk,<br><br>I see you are using VBScript. I don't know the exact syntax but there is the equivalent in VBScript of the following Javascript:<br><br>var s = new String(Request.Form(&quot;ID&quot;));<br>// s is now &quot;10200;3;20010;4;10110;2&quot; notice I got rid of the first semicolon.<br><br>var myarray = s.split(&quot;;&quot;);<br>// myarray now has 6 elements<br>// 0 = 10200<br>// 1 = 3<br>// 2 = 20010<br>// 3 = 4<br>// 4 = 10110<br>// 5 = 2<br>var count = myarray.length;<br>// count is now equal to 6<br><br>Hope this helps<br>-pete
 
in VBscript:<br>a = split(&quot;10200;3;20010;4;10110;2&quot;,&quot;;&quot;)<br>NumberOfEntries = ubound(a) + 1 <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Thanks.&nbsp;&nbsp;I have seen the ubound command before.&nbsp;&nbsp;That's just what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top