Author |
Topic |
GoodMorningSky
Junior Member
122 Posts |
Posted - 25 November 2002 : 00:37:00
|
I think I can put any type in Seesion. Like this. in test1.asp
Dim arr arr=Array("a", "b", "c") Session("test")=arr
and in test2.asp
Dim arr arr=Session("test") For count=1 to UBound(arr) ... Next
This gives me error( Type mismatch: in UBound(arr)) What's problem? DO I need type cast here? then How?
Thank you..
|
Software Engineer. MCSD.NET, SCWCD |
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 00:51:30
|
In your example arr isn't an array hence the error.
Dim Arr(1)
Arr(0) = Array("a","b",c") ' Note this is an Array within an Array
Arr(1) = Array(1,2,3)
Session("test") = Arr
.....
Dim Arr, i
Arr = Session("test")
for i = 0 to ubound(Arr)
Response.Write Arr(i)(0)
Response.Write Arr(i)(1)
Response.Write Arr(i)(2)
next
|
Kiwihosting.Net - The Forum Hosting Specialists
|
Edited by - Gremlin on 25 November 2002 00:54:06 |
|
|
GoodMorningSky
Junior Member
122 Posts |
Posted - 25 November 2002 : 01:08:20
|
Thank you for reply
But it gives me error
Microsoft VBScript compilation (0x800A0409) Unterminated string constant /GMSForum/MOD/Dictionary/Add3.asp, line 25, column 69 Arr(0) = Array("a","b",c") ' Note this is an Array within an Array --------------------------------------------------------------------^ I just tested your code.
And How can I do one dimention array?
|
Software Engineer. MCSD.NET, SCWCD |
|
|
GoodMorningSky
Junior Member
122 Posts |
Posted - 25 November 2002 : 01:14:21
|
Above error comes from missing " before c". After correcting that, It still gives me
Error Type: Microsoft VBScript runtime (0x800A000D) Type mismatch: 'ubound' /GMSForum/MOD/Dictionary/Add4.asp, line 10
for your code.
Dim Arr, i Arr = Session("test") for i = 0 to ubound(Arr) Response.Write Arr(i)(0) Response.Write Arr(i)(1) Response.Write Arr(i)(2) next
Thank you. Please reply.. |
Software Engineer. MCSD.NET, SCWCD |
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 01:32:29
|
If you want a one dimensional array you would normally use
Dim Arr(2)
Arr(0) = "a"
Arr(1) = "b"
Arr(2) = "c"
Session("test") = Arr
Dim Arr, i
Arr = Session("test")
for i = 0 to ubound(Arr)
Response.Write Arr(i) & "<br>"
next
However, your first example should be able to be corrected by using
Dim Arr
Arr = Array("a","b","c")
Session("test") = Arr
Dim Arr, i
Arr = Session("test")
for i = 0 to ubound(Arr,1)
Response.Write Arr(i) & "<br>"
next
|
Kiwihosting.Net - The Forum Hosting Specialists
|
Edited by - Gremlin on 25 November 2002 01:34:35 |
|
|
GoodMorningSky
Junior Member
122 Posts |
Posted - 25 November 2002 : 01:49:57
|
I just test your code again. But, Still give me same eror Type mismatch: 'ubound' /GMSForum/MOD/Dictionary/Add4.asp, line 10
Dim Arr Arr = Array("a","b","c") Session("test111") = Arr
Response.Redirect("Add4.asp")
<% Dim Arr, i Arr = Session("test111") for i = 0 to ubound(Arr,1) Response.Write Arr(i) & "<br>" next
%> |
Software Engineer. MCSD.NET, SCWCD |
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 01:59:20
|
I just tried it myself, works perfectly for me. |
Kiwihosting.Net - The Forum Hosting Specialists
|
|
|
GoodMorningSky
Junior Member
122 Posts |
Posted - 25 November 2002 : 02:12:17
|
Thank you for replay.. But, I still get same error in Ubound. Could you take a look below, it's whole code. I test it brinkster after upload. It doesn't work. I think IIS doesn't have problem, my code. does. Please take a look if you don't mind.
Add3.asp
<%@ Language=VBScript %> <% Option Explicit %> <HTML> <HEAD> <% Dim WordType, NumOfMeaning WordType=Session("Add_Type") 'Word Type' NumOfMeaning=Cint(Session("Add_Number")) 'NUmber of meaings to enter
if Request.QueryString("Method")<>Null then 'collecte all info and save it to Session Dim typeSessionName Dim pron, past,pres pron=Request("tfPron") if Session("Add_Type")="vi" Or Session("Add_Type")="vt" then past=Request("tfPast") pres=Request("tfPres") end if Dim i, meanings(), etimologies() ReDim meanings(CInt(NumOfMeaning)) ReDim etimologies(CInt(NumOfMeaning)) Dim difficulties(), usages() ReDim difficulties(CInt(NumOfMeaning)) ReDim usages(CInt(NumOfMeaning)) For i=0 to NumOfMeaning meanings(i)=Request("taMeaning" & CStr(i)) etimologies(i)=Request("tfEtimo"& CStr(i)) difficulties(i)=Request("seDif"& CStr(i)) usages(i)=Request("taUsage"& CStr(i)) Next Dim Arr Arr = Array("a","b","c") Session("test111") = Arr
Response.Redirect("Add4.asp") Session(typeSessionName) elseif Request.QueryString("Method")="finish" then Response.Redirect("Add4.asp") elseif Request.QueryString("Method")="addMore" then Session("Add_TypesAdded")=Session("Add_TypedsAdded") & ";" & WordType Response.Redirect("Add2.asp") end if
%> <meta name="vs_showGrid" content="False"> <meta name="GENERATOR" Content="Microsoft Visual Studio.NET 7.0"> </HEAD> <body> Test: Inputs<br> <% Response.Write pron &" " & past & " " &pres & "<br>" Dim k For k=0 to NumOfMeaning 'Response.Write " " &" " & CStr(meanings(i)) & "<br>" ' Response.Write " " & i & " " & etimologies(i)& "<br>" ' Response.Write " " & i & " " & difficulties(i)& "<br>" ' Response.Write " " & i & " " & usages(i)& "<br>" Next %> <% '= meanings(0) %> Test2: <% '=meanings(1) %> <P><FONT face="Arial"><FONT size="5"><FONT face="Courier">Add Word Wizard <FONT size="4"><STRONG>Step 3</STRONG></FONT></FONT></FONT></FONT></P> <form id="add3Form" name="add3Form" method="post" action="Add3.asp"> <P><FONT face="Arial"><FONT size="5"><FONT face="Courier"><FONT size="4">Word:<BR> Type for meaning:</FONT></FONT></FONT></FONT></P> <FONT face="Arial"><FONT size="5"><FONT face="Courier"><FONT size="4"> <UL> <LI> Pronounciation: <INPUT id="tfPron" type="text" name="tfPron" maxLength="30"> <%if Session("Add_Type")="vi" Or _ Session("Add_Type")="vt" then %> <LI> <FONT face="Arial"><FONT face="Courier">Present word Form:</FONT> <INPUT id="tfPres" type="text" name="tfPres" maxLength="30"></FONT> <LI> Past word Form: <INPUT id="tfPast" type="text" name="tfPast" maxLength="30"> <%end if%> <LI> Meanings </LI> <UL> <% Dim Count For Count=1 to NumOfMeaning %> <LI> Meaning <%=Count%><BR> <TEXTAREA id="taMeaning" name=<%Response.Write "taMeaning" & CStr(Count) %> rows="3" cols="54"></TEXTAREA> <LI> <FONT face="Arial"><FONT face="Courier">Etimoloty</FONT>: <INPUT id="tfEtimo" type="text" name=<%Response.Write "tfEtimo" & CStr(Count)%>></FONT> <LI> <FONT face="Arial"><FONT face="Courier">Difficulty</FONT>: <SELECT id="seDif" name=<%Response.Write "seDif" & CStr(Count)%>> <OPTION value="1" selected>1</OPTION> <OPTION value="2">2</OPTION> <OPTION value="3">3</OPTION> <OPTION value="4">4</OPTION> <OPTION value="5">5</OPTION> <OPTION value="6">6</OPTION> <OPTION value="7">7</OPTION> <OPTION value="8">8</OPTION> <OPTION value="9">9</OPTION> <OPTION value="10">10</OPTION> </SELECT></FONT></LI></UL> <UL> <LI> <FONT face="Arial"><FONT face="Courier">Usage</FONT>: <BR> <TEXTAREA id="taUsage" name=<%Response.Write "seDif" & CStr(Count)%> rows="3" cols="54"></TEXTAREA> </FONT> </FONT></FONT></FONT></FONT> </LI> <% Next %> </UL></UL> <P> <hr> </P> <P><FONT face="Arial"><img src="file:///C:\MyDoc\Comp440\GoodMoringSkyForum\MOD\Dictionary\images\next.gif" border=0 alt="Add More Meaning" hspace=0 onclick=Process('addMore') align=right></FONT> <FONT face="Arial"><img src="file:///C:\MyDoc\Comp440\GoodMoringSkyForum\MOD\Dictionary\images\next.gif" border=0 alt="Finish" hspace=0 onclick=Process('finish') align=right></FONT></P> </form> <script language="javascript"> function Process(Method) { document.location="Add3.asp?Method="+Method; } </script> </body> </HTML>
Add4.asp <%@ Language=VBScript %> <HTML> <HEAD> <meta name="GENERATOR" Content="Microsoft Visual Studio.NET 7.0"> </HEAD> <body> <% Dim Arr, i Arr = Session("test111") for i = 0 to ubound(Arr,1) Response.Write Arr(i) & "<br>" next
%> <P><FONT size="5"><FONT face="Courier">Add Word Wizard <FONT size="4"><STRONG>Step End<BR> </STRONG></FONT></FONT></FONT> </P> <UL> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Word:</FONT></FONT></FONT></LI> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Synonym:</FONT></FONT></FONT></LI> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Antonym:</FONT></FONT></FONT></LI> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Pre/Subfix</FONT></FONT></FONT></LI> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Inflected Word Form:</FONT></FONT></FONT></LI> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Type:</FONT></FONT></FONT></LI> <UL> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Prenounciation:</FONT></FONT></FONT></LI> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Present form:</FONT></FONT></FONT></LI> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Past form:</FONT></FONT></FONT></LI></UL> <LI> <FONT size="5"><FONT face="Courier"><FONT size="4">Meanings</FONT></FONT></FONT></LI></UL> <P><FONT size="5"><FONT face="Courier"><FONT size="4"></FONT></FONT></FONT> </P> <P><FONT size="5"><FONT face="Courier"><FONT size="4"><IMG alt="" src="" name="OK"><IMG alt="" src=""></P> </FONT></FONT></FONT> </body> </HTML>
|
Software Engineer. MCSD.NET, SCWCD |
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 02:22:39
|
The problem is your not actually executing the code the sets up the array in add3.asp before redirecting to add4.asp
|
Kiwihosting.Net - The Forum Hosting Specialists
|
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 02:35:21
|
In add3.asp
Change this line
if Request.QueryString("Method")<>Null then to
if Request.QueryString("Method") <> "" then |
Kiwihosting.Net - The Forum Hosting Specialists
|
|
|
GoodMorningSky
Junior Member
122 Posts |
Posted - 25 November 2002 : 02:44:47
|
Thank you very much. You are right. I have to check it. |
Software Engineer. MCSD.NET, SCWCD |
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 03:07:07
|
Youre Welcome |
Kiwihosting.Net - The Forum Hosting Specialists
|
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 25 November 2002 : 04:02:15
|
Dim Arr, i
Arr = Session("test111")
for i = 0 to ubound(Arr,1)
Response.Write Arr(i) & "<br>"
next
Looks like you are using a single dimension array so just use
for i = 0 to ubound(Arr)
Response.Write Arr(i) & "<br>"
next
It will be better to check if the values in the variable is an array
if IsArray(Arr) then
for i = 0 to ubound(Arr)
Response.Write Arr(i) & "<br>"
next
else
...
end if
|
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 04:17:08
|
We already got there in the end, but thanks GB.
It's becuase the single dimension array when defined like that it never gets set a sub-type of array it remains variant type so ubound(arr) will never work, but ubound(arr,1) will.
|
Kiwihosting.Net - The Forum Hosting Specialists
|
Edited by - Gremlin on 25 November 2002 04:17:43 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 25 November 2002 : 08:02:04
|
I will still be thinking if it works.
quote: ...ubound(arr) will never work, but ubound(arr,1) will.
ubound([arrayname]) will give an error only if the contents of the variable are not an array. ubound(arrayname, 1) is same as ubound(arrayname).
I tested the code used by GoodMorningSky as below:
Dim Arr
Arr = Session("test111")
if isArray(Arr) then
'continue
elseif Arr = "" then
Arr = Array("a","b","c")
end if
Session("test111") = Arr
for i = 0 to ubound(Arr)
Response.Write Arr(i) & "<br>"
next |
|
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 25 November 2002 : 08:14:17
|
I never tested that, but I did find an article that said if it was not specifically defined as an Array then ubound would not work becuase the variable was still variant typed. Perhaps the article was an older reference to ASP2 or even older ?
hmm actually no I think I did test that and got an type error. *weird* |
Kiwihosting.Net - The Forum Hosting Specialists
|
Edited by - Gremlin on 25 November 2002 08:15:37 |
|
|
Topic |
|