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

Arrays and sessions

Status
Not open for further replies.

nam4520

Programmer
Jan 7, 2003
14
US
will someone please tell me why I'm getting the 'type mismatch' error on this piece of code. the error comes from the 'for i= 0 to ubound(sysmods)' line. thanks


DIM QRY2, RST2, SYSMODS
QRY2= "select P.PRE_SYSMOD_NO, F.TAPE_NO from FIXPRE P, FIX F where P.SYSMOD_NO ='" & SESSION("SYSMODS") & "'"_
& " and F.SYSMOD_NO = P.PRE_SYSMOD_NO"_
& " and F.TAPE_NO > '" & TAPE_no & "'"_
& " order by PRE_SYSMOD_NO DESC;"
SET RST2= cnn.Execute(QRY2)
dim myarray(), num, i
num=0
'num =myarray(0)
Response.Write(&quot;<table>&quot;)
Call gettape(sysmod_no)
DO WHILE NOT(RST2.EOF)
num=num + 1
redim preserve myarray(num)
myarray(num)= rst2(&quot;pre_sysmod_no&quot;)
SESSION(&quot;SYSMODS&quot;)= myarray(num) & &quot;<br>&quot;
SYSMODS=SESSION(&quot;SYSMODS&quot;)
rst2.movenexT
loop

for i = 0 to UBOUND(SYSMODS)
Response.Write(sysmods(i))
next
 
Try this

<% If IsArray(SYSMODS) Then
For i = 0 TO Ubound(SYSMODS)
Response.Write SYSMODS(i)
Next
Else
Response.Write &quot;SYSMODS is not an Array&quot;
Response.End
End If %>
 
there is an error here
SESSION(&quot;SYSMODS&quot;)= myarray(num) & &quot;<br>&quot;
here only the last value of myarray is stored and NOT the array
therefore SYSMODS will also not be an array
try this
SESSION(&quot;SYSMODS&quot;)= myarray & &quot;<br>&quot;
 
Here is full source for this.

Code:
' Checks if variable is an array
If IsArray(Session(&quot;SYSMODS&quot;)) Then

	' store in local variable
	myArray = Session(&quot;SYSMODS&quot;)
	currItem = 0
	
	' loop through each element of array
	While currItem <= Ubound(myArray, 1)

		' html encode the text in array element, good if you working with database
		Response.Write(&quot;myArray(&quot; & currItem & &quot;) = &quot; & Server.HTMLEncode(myArray(currItem) & &quot;<br/>&quot;)

		' increment our counter
		currItem = currItem + 1

		' loop through the next element
	Wend
End If

' Destroy
Set currItem = Nothing
Erase myArray
Session.Contents.Remove &quot;myArray&quot;
_______________________________
regards,
Brian
AOL IM: FreelanceGaines
AG00280_.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top