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

Array Object

Status
Not open for further replies.

mgonzalez

Programmer
Aug 2, 2000
51
MX


Anyone could tell me the way to make a array and then get their values I have understood that I have to do something like this:

<%
'Creating and initializing the array(unidimentional)
Dim MyArray()
Redim MyArray(request.form.count)

for each item in request.form
MyArray = request.form(item)
'keep the values of the previous form
next


'Geting the values from array(fifth elemment in a array) and using the values in a select
select * from x where y = session(MyArray(5))
%>
'Make it like array session type
session(&quot;array1&quot;) = MyArray

Thanks
[sig][/sig]
 
Almost!

First, you'll need to tell the script engine which array element to put each value into.

dim indexcounter
for each item in request.form
MyArray(indexcounter) = request.form(item)
indexcounter = indexcounter + 1
next

second, since arrays are zero based, to get the fifth element, you'd use an index of 4, not 5.
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 


I have did before but when I want assign de request.form (item) to MyArray doesn´t show annything [sig][/sig]
 
I'm not sure I understand your problem, but I'll take a guess. If you're trying to access the array directly from the session variable, that's the problem. You need to assign it to another variable in your page.

Assume that on the first page, you've used the code in my previous post. You now have an array called MyArray. You can store the array in a session variable like this:
session(&quot;MyArrayVariable&quot;)=MyArray.

when you want to retrieve the contents, you can't use the session variable directly. You need to copy the contents to another variable:
MyNewArray=session(&quot;MyArrayVariable&quot;)
response.write MyNewArray(1)
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Yes a just did exactly that but when I want to do this in the second page

MyNewArray=session(&quot;MyArrayVariable&quot;)

the page doesn't show anything
[sig][/sig]
 
Here's a page that shows what I mean:
Code:
<html><head></head><body>
<% 
dim MyArray(2)
if request.form.count = 0 then
    MyArray(0) = &quot;zero&quot;
    MyArray(1) = &quot;one&quot;
    MyArray(2) = &quot;two&quot;
    session(&quot;MyArrayVariable&quot;) = MyArray
%>
    <form action=&quot;test.asp&quot; method=&quot;post&quot;>
    <input type='hidden' name='junk'>
    <input type='submit' value='submit' >
    </form>
<%
else
    dim NewArray
    dim ArrayMember
    NewArray = session(&quot;MyArrayVariable&quot;)
    if isArray(NewArray) then
        for each ArrayMember in NewArray
            response.write ArrayMember & &quot;<BR>&quot;
        next
    else
        response.write &quot;Session Variable does not contain an array&quot;
    end if
end if
%>
</body>
<html>
[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Now I´m not sure what want to do in the previous eaxmaple.Are you telling me that I have to check the local array whith the array function after of assign the session to local array? [sig][/sig]
 
Now I´m not sure what want to do in the previous eaxmaple.Are you telling me that I have to
check the local array whith the array function after of assign the session to local array? [sig][/sig]
 
What I'm saying is:
you cannot directly put/get array values to/from a session variable. You must use an interim variable.


To store an array in a session variable:


1) declare a local variable for your array
dim a(2)


2) populate your array[/color]
a(0)=&quot;0&quot;
a(1)=&quot;1&quot;
a(2)=&quot;2&quot;


3) copy the local variable to a session variable
session(&quot;savedarray&quot;) = a


To retrieve values from an array that was stored in a session variable:


1) declare a local variable
Dim b


2) Copy the array from the session variable to the local variable:
b=session(&quot;savedarray&quot;)


3) Retrieve the individual values from the local variable:
response.write b(0) & &quot;<BR>&quot;
response.write b(1) & &quot;<BR>&quot;
response.write b(2) & &quot;<BR>&quot;




[sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top