Need help in Vbscript error 
Author Message
 Need help in Vbscript error

Hi
  I have following error
       Microsoft VBScript runtime (0x800A0009)
       Subscript out of range: 'k'
       /OnlineMall/Cart.asp, line 75

My following ASP page is getting values from previous page using
response.write("txtQuantity") method. I have errors in parsing through array
made by split function.

My ASP code is


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<%
set con=server.CreateObject("ADODB.Connection")
con.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\OnlineMall\ProductDB.mdb;Persist Security
Info=False"
mySQL="SELECT * from products"
Set rs=con.Execute(mySQL)
Response.Write(Request.Form("txtQuantity"))
strValue=Request.Form("txtQuantity")
 sQuantity=split(strValue,",")
for k=0 to ubound(sQuantity)
 Response.Write(sQuantity(k) & "<br>")
next
 %>
 <table border="1">
  <tr>
  <td>
       Title
  </td>
  <td>
       Price
  </td>
  <td>
       Quantity
  </td>
  <td>
       Total Price
  </td>
  </tr>
 <%
k=0
do while not rs.eof
Response.Write(sQuantity(k)) --------------------------------- i have error
on this line
'if cint(sQuantity(k)) > 0 then
  ' if sQuantity(k) <> " " then
%>
<tr>
  <td>
       <%=rs("Title")%>
  </td>
  <td>
       <%=rs("Price")%>
  </td>
  <td>
   <%

    ' if sQuantity(k) <> " " then

    'Response.write(sQuantity(k))

    ' else

    Response.write("0")

      ' end if

       %>
  </td>
  <td>

        <%

   '  dim stuff

    'strPrice=rs.fields("Price")

    'if sQuantity(k) <> " " then

         ' stuff = strPrice * sQuantity(k)
           '  Response.Write(strPrice)
       'end if

    Response.Write(stuff)

        %>

  </td>
  </td>

 </tr>
<%
'end if
rs.movenext
k=k+1

loop

%>
</table>
<%
rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
%>

</BODY>
</HTML>



Sat, 03 Jan 2004 13:51:06 GMT  
 Need help in Vbscript error
My guess is that since you're using zero-indexed arrays, you need to use a
line like

 for k=0 to ubound(sQuantity) - 1
because sQuantity(ubound(sQuantity)) will be one more than the highest
acceptable index (being zero-based)

-Robert


Quote:
> Hi
>   I have following error
>        Microsoft VBScript runtime (0x800A0009)
>        Subscript out of range: 'k'
>        /OnlineMall/Cart.asp, line 75

> My following ASP page is getting values from previous page using
> response.write("txtQuantity") method. I have errors in parsing through
array
> made by split function.

> My ASP code is


> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
> </HEAD>
> <BODY>

> <%
> set con=server.CreateObject("ADODB.Connection")
> con.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=C:\Inetpub\wwwroot\OnlineMall\ProductDB.mdb;Persist Security
> Info=False"
> mySQL="SELECT * from products"
> Set rs=con.Execute(mySQL)
> Response.Write(Request.Form("txtQuantity"))
> strValue=Request.Form("txtQuantity")
>  sQuantity=split(strValue,",")
> for k=0 to ubound(sQuantity)
>  Response.Write(sQuantity(k) & "<br>")
> next
>  %>
>  <table border="1">
>   <tr>
>   <td>
>        Title
>   </td>
>   <td>
>        Price
>   </td>
>   <td>
>        Quantity
>   </td>
>   <td>
>        Total Price
>   </td>
>   </tr>
>  <%
> k=0
> do while not rs.eof
> Response.Write(sQuantity(k)) --------------------------------- i have
error
> on this line
> 'if cint(sQuantity(k)) > 0 then
>   ' if sQuantity(k) <> " " then
> %>
> <tr>
>   <td>
>        <%=rs("Title")%>
>   </td>
>   <td>
>        <%=rs("Price")%>
>   </td>
>   <td>
>    <%

>     ' if sQuantity(k) <> " " then

>     'Response.write(sQuantity(k))

>     ' else

>     Response.write("0")

>       ' end if

>        %>
>   </td>
>   <td>

>         <%

>    '  dim stuff

>     'strPrice=rs.fields("Price")

>     'if sQuantity(k) <> " " then

>          ' stuff = strPrice * sQuantity(k)
>            '  Response.Write(strPrice)
>        'end if

>     Response.Write(stuff)

>         %>

>   </td>
>   </td>

>  </tr>
> <%
> 'end if
> rs.movenext
> k=k+1

> loop

> %>
> </table>
> <%
> rs.Close
> Set rs = Nothing
> con.Close
> Set con = Nothing
> %>

> </BODY>
> </HTML>



Sat, 03 Jan 2004 23:01:20 GMT  
 Need help in Vbscript error
Hi Dunn

Thanks for the suggestion. I tried that too. My array is working fine, but
when it comes to code in do-while-loop segment i have error on

line ---- Response.Write(sQuantity(k))----- if i comment this line and other
conatining sQuantity(k) array i dot not et error. if i have those lines
commented then my array variable shows contents, if i use following code

for k=0 to ubound(sQuantity)

Response.write(sQuantity(k))

next

Still need help!!

Thanks in advance


Quote:
> My guess is that since you're using zero-indexed arrays, you need to use a
> line like

>  for k=0 to ubound(sQuantity) - 1
> because sQuantity(ubound(sQuantity)) will be one more than the highest
> acceptable index (being zero-based)

> -Robert



> > Hi
> >   I have following error
> >        Microsoft VBScript runtime (0x800A0009)
> >        Subscript out of range: 'k'
> >        /OnlineMall/Cart.asp, line 75

> > My following ASP page is getting values from previous page using
> > response.write("txtQuantity") method. I have errors in parsing through
> array
> > made by split function.

> > My ASP code is


> > <HTML>
> > <HEAD>
> > <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
> > </HEAD>
> > <BODY>

> > <%
> > set con=server.CreateObject("ADODB.Connection")
> > con.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> > Source=C:\Inetpub\wwwroot\OnlineMall\ProductDB.mdb;Persist Security
> > Info=False"
> > mySQL="SELECT * from products"
> > Set rs=con.Execute(mySQL)
> > Response.Write(Request.Form("txtQuantity"))
> > strValue=Request.Form("txtQuantity")
> >  sQuantity=split(strValue,",")
> > for k=0 to ubound(sQuantity)
> >  Response.Write(sQuantity(k) & "<br>")
> > next
> >  %>
> >  <table border="1">
> >   <tr>
> >   <td>
> >        Title
> >   </td>
> >   <td>
> >        Price
> >   </td>
> >   <td>
> >        Quantity
> >   </td>
> >   <td>
> >        Total Price
> >   </td>
> >   </tr>
> >  <%
> > k=0
> > do while not rs.eof
> > Response.Write(sQuantity(k)) --------------------------------- i have
> error
> > on this line
> > 'if cint(sQuantity(k)) > 0 then
> >   ' if sQuantity(k) <> " " then
> > %>
> > <tr>
> >   <td>
> >        <%=rs("Title")%>
> >   </td>
> >   <td>
> >        <%=rs("Price")%>
> >   </td>
> >   <td>
> >    <%

> >     ' if sQuantity(k) <> " " then

> >     'Response.write(sQuantity(k))

> >     ' else

> >     Response.write("0")

> >       ' end if

> >        %>
> >   </td>
> >   <td>

> >         <%

> >    '  dim stuff

> >     'strPrice=rs.fields("Price")

> >     'if sQuantity(k) <> " " then

> >          ' stuff = strPrice * sQuantity(k)
> >            '  Response.Write(strPrice)
> >        'end if

> >     Response.Write(stuff)

> >         %>

> >   </td>
> >   </td>

> >  </tr>
> > <%
> > 'end if
> > rs.movenext
> > k=k+1

> > loop

> > %>
> > </table>
> > <%
> > rs.Close
> > Set rs = Nothing
> > con.Close
> > Set con = Nothing
> > %>

> > </BODY>
> > </HTML>



Mon, 05 Jan 2004 12:47:43 GMT  
 Need help in Vbscript error
In the 1st loop you're walking the array up to the upper bound.  In the 2nd case, you're walking the
recordset and assuming that the number of records before you hit rs.EOF won't exceed the upper bound
of the array, which is apparently not the case.  At some point, the k=k+1 after the rs.MoveNext at
the end of the loop puts k beyond the upper bound of sQuantity.

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> Hi Dunn

> Thanks for the suggestion. I tried that too. My array is working fine, but
> when it comes to code in do-while-loop segment i have error on

> line ---- Response.Write(sQuantity(k))----- if i comment this line and other
> conatining sQuantity(k) array i dot not et error. if i have those lines
> commented then my array variable shows contents, if i use following code

> for k=0 to ubound(sQuantity)

> Response.write(sQuantity(k))

> next

> Still need help!!

> Thanks in advance



> > My guess is that since you're using zero-indexed arrays, you need to use a
> > line like

> >  for k=0 to ubound(sQuantity) - 1
> > because sQuantity(ubound(sQuantity)) will be one more than the highest
> > acceptable index (being zero-based)

> > -Robert



> > > Hi
> > >   I have following error
> > >        Microsoft VBScript runtime (0x800A0009)
> > >        Subscript out of range: 'k'
> > >        /OnlineMall/Cart.asp, line 75

> > > My following ASP page is getting values from previous page using
> > > response.write("txtQuantity") method. I have errors in parsing through
> > array
> > > made by split function.

> > > My ASP code is


> > > <HTML>
> > > <HEAD>
> > > <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
> > > </HEAD>
> > > <BODY>

> > > <%
> > > set con=server.CreateObject("ADODB.Connection")
> > > con.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> > > Source=C:\Inetpub\wwwroot\OnlineMall\ProductDB.mdb;Persist Security
> > > Info=False"
> > > mySQL="SELECT * from products"
> > > Set rs=con.Execute(mySQL)
> > > Response.Write(Request.Form("txtQuantity"))
> > > strValue=Request.Form("txtQuantity")
> > >  sQuantity=split(strValue,",")
> > > for k=0 to ubound(sQuantity)
> > >  Response.Write(sQuantity(k) & "<br>")
> > > next
> > >  %>
> > >  <table border="1">
> > >   <tr>
> > >   <td>
> > >        Title
> > >   </td>
> > >   <td>
> > >        Price
> > >   </td>
> > >   <td>
> > >        Quantity
> > >   </td>
> > >   <td>
> > >        Total Price
> > >   </td>
> > >   </tr>
> > >  <%
> > > k=0
> > > do while not rs.eof
> > > Response.Write(sQuantity(k)) --------------------------------- i have
> > error
> > > on this line
> > > 'if cint(sQuantity(k)) > 0 then
> > >   ' if sQuantity(k) <> " " then
> > > %>
> > > <tr>
> > >   <td>
> > >        <%=rs("Title")%>
> > >   </td>
> > >   <td>
> > >        <%=rs("Price")%>
> > >   </td>
> > >   <td>
> > >    <%

> > >     ' if sQuantity(k) <> " " then

> > >     'Response.write(sQuantity(k))

> > >     ' else

> > >     Response.write("0")

> > >       ' end if

> > >        %>
> > >   </td>
> > >   <td>

> > >         <%

> > >    '  dim stuff

> > >     'strPrice=rs.fields("Price")

> > >     'if sQuantity(k) <> " " then

> > >          ' stuff = strPrice * sQuantity(k)
> > >            '  Response.Write(strPrice)
> > >        'end if

> > >     Response.Write(stuff)

> > >         %>

> > >   </td>
> > >   </td>

> > >  </tr>
> > > <%
> > > 'end if
> > > rs.movenext
> > > k=k+1

> > > loop

> > > %>
> > > </table>
> > > <%
> > > rs.Close
> > > Set rs = Nothing
> > > con.Close
> > > Set con = Nothing
> > > %>

> > > </BODY>
> > > </HTML>



Mon, 05 Jan 2004 11:56:36 GMT  
 Need help in Vbscript error
i am getting ubound type mismactch error

<%  
        scartitemnums = session("cartitemnumarray")
        ncartitemqtys = session("cartitemqtyarray")
        ncartitemsample = session("cartitemsamplearray")
        ncartitemquote = session("cartitemquotearray")
        'Response.Write scartitemnums

        nnumcartitems = ubound(scartitemnums)

        'Response.Write nnumcartitems
        sMode = request.querystring("mode")
        select case request.form("cmdSubmit")
                case "Finished Shopping"
                        sMode = "finished"
                case "edit shopping"
                        sMode = "recalc"
                case "Continue Shopping"
                        sMode = "continue"
        end select
        dim sitemno
        dim sitems
if sMode = "add" then
        nthisitemindex = 0
        sitemno = Request.Form("item_code")
if nnumcartitems > 0 then
        'response.write nNumCartItems
for i=1 to nnumcartitems
        if scartitemnums(i)     = sitemno then
        nthisitemindex = i
exit for
end if
        next
end if
        c=request.Form("order")
        a=request.Form("quote")
        b=request.Form("sample")
'session("cartitemqtyarray")= session("cartitemqtyarray") + cint(c)
'session("cartitemsamplearray")= session("cartitemsamplearray") + cint(b)
'session("cartitemquotearray")= session("cartitemquotearray") + cint(a)
'session("newc") = session("newc") +  cint(c)
'Response.Write session("newc")
if nthisitemindex = 0 then
        nthisitemindex = nnumcartitems + 1
        nnumcartitems = nnumcartitems + 1
        redim Preserve scartitemnums(nthisitemindex)
        redim Preserve ncartitemqtys(nthisitemindex)
        redim Preserve ncartitemsample(nthisitemindex)
        redim Preserve ncartitemquote(nthisitemindex)
        scartitemnums(nthisitemindex) = sitemno
        ncartitemqtys(nthisitemindex) = cint(c)
        ncartitemquote(nthisitemindex) = cint(a)
        ncartitemsample(nthisitemindex) = cint(b)
     'response.write ncartitemqtys(nthisitemindex)
'response.write c
else
        ncartitemqtys(nthisitemindex)  = cint(ncartitemqtys(nthisitemindex))  + cint(c)
        ncartitemquote(nthisitemindex) = cint(ncartitemquote(nthisitemindex)) + cint(a)
        ncartitemsample(nthisitemindex)= cint(ncartitemsample(nthisitemindex))+ cint(b)
        response.write ncartitemqtys(nthisitemindex)
end if
        session("cartitemnumarray")= scartitemnums
        session("cartitemqtyarray")= ncartitemqtys
        session("cartitemquotearray")= ncartitemquote
        session("cartitemqsamplearray")= ncartitemsample
        nnumcartitems = ubound(scartitemnums)
end if
if sMode = "continue" or sMode = "recalc" or sMode = "finished" then
 for i=1 to nnumcartitems
        nthisqty = int(Request.Form("order" & i))
        ncartitemqtys(i) = nthisqty
        nthisquote = int(Request.Form("quote" & i))
        ncartitemquote(i) = nthisquote
        nthissample = int(Request.Form("sample" & i))
        ncartitemsample(i) = nthissample
 next
        session("cartitemnumarray") = scartitemnums
        session("cartitemqtyarray") = ncartitemqtys
        session("cartitemquotearray") = ncartitemquote
        session("cartitemqsamplearray") = ncartitemsample
end if

select case sMode
        case "continue"
        response.redirect("searchcriteria.asp")
end select
'end if
%>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 06 Jan 2004 20:29:23 GMT  
 Need help in Vbscript error
If you get a type mismatch on ubound() then what you passed to ubound() is not an array.  On the 1st
time through the page, there are no session variables to retrieve (unless perhaps you initialized
them in Session_OnStart() in global.asa).

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> i am getting ubound type mismactch error

> <%
> scartitemnums = session("cartitemnumarray")
> ncartitemqtys = session("cartitemqtyarray")
> ncartitemsample = session("cartitemsamplearray")
> ncartitemquote = session("cartitemquotearray")
> 'Response.Write scartitemnums

> nnumcartitems = ubound(scartitemnums)

> 'Response.Write nnumcartitems
> sMode = request.querystring("mode")
> select case request.form("cmdSubmit")
> case "Finished Shopping"
> sMode = "finished"
> case "edit shopping"
> sMode = "recalc"
> case "Continue Shopping"
> sMode = "continue"
> end select
> dim sitemno
> dim sitems
> if sMode = "add" then
> nthisitemindex = 0
> sitemno = Request.Form("item_code")
> if nnumcartitems > 0 then
> 'response.write nNumCartItems
> for i=1 to nnumcartitems
> if scartitemnums(i) = sitemno then
> nthisitemindex = i
> exit for
> end if
> next
> end if
> c=request.Form("order")
> a=request.Form("quote")
> b=request.Form("sample")
> 'session("cartitemqtyarray")= session("cartitemqtyarray") + cint(c)
> 'session("cartitemsamplearray")= session("cartitemsamplearray") + cint(b)
> 'session("cartitemquotearray")= session("cartitemquotearray") + cint(a)
> 'session("newc") = session("newc") +  cint(c)
> 'Response.Write session("newc")
> if nthisitemindex = 0 then
> nthisitemindex = nnumcartitems + 1
> nnumcartitems = nnumcartitems + 1
> redim Preserve scartitemnums(nthisitemindex)
> redim Preserve ncartitemqtys(nthisitemindex)
> redim Preserve ncartitemsample(nthisitemindex)
> redim Preserve ncartitemquote(nthisitemindex)
> scartitemnums(nthisitemindex) = sitemno
> ncartitemqtys(nthisitemindex) = cint(c)
> ncartitemquote(nthisitemindex) = cint(a)
> ncartitemsample(nthisitemindex) = cint(b)
>      'response.write ncartitemqtys(nthisitemindex)
> 'response.write c
> else
> ncartitemqtys(nthisitemindex)  = cint(ncartitemqtys(nthisitemindex))  + cint(c)
> ncartitemquote(nthisitemindex) = cint(ncartitemquote(nthisitemindex)) + cint(a)
> ncartitemsample(nthisitemindex)= cint(ncartitemsample(nthisitemindex))+ cint(b)
> response.write ncartitemqtys(nthisitemindex)
> end if
> session("cartitemnumarray")= scartitemnums
> session("cartitemqtyarray")= ncartitemqtys
> session("cartitemquotearray")= ncartitemquote
> session("cartitemqsamplearray")= ncartitemsample
> nnumcartitems = ubound(scartitemnums)
> end if
> if sMode = "continue" or sMode = "recalc" or sMode = "finished" then
>  for i=1 to nnumcartitems
> nthisqty = int(Request.Form("order" & i))
> ncartitemqtys(i) = nthisqty
> nthisquote = int(Request.Form("quote" & i))
> ncartitemquote(i) = nthisquote
> nthissample = int(Request.Form("sample" & i))
> ncartitemsample(i) = nthissample
>  next
> session("cartitemnumarray") = scartitemnums
> session("cartitemqtyarray") = ncartitemqtys
> session("cartitemquotearray") = ncartitemquote
> session("cartitemqsamplearray") = ncartitemsample
> end if

> select case sMode
> case "continue"
> response.redirect("searchcriteria.asp")
> end select
> 'end if
> %>

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Tue, 06 Jan 2004 22:37:28 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Preload Object Error (Need Help, Trying to Learn VBScript)

2. Need Help with Microsoft VBScript compilation error

3. VBscript - Error 424 Object Required - NEED a FIX

4. vbscript error - need assistance

5. Need to send an email from a vbscript if I get an error

6. Req: Help needed with error message UNEXPECTED ERROR

7. Error 3251, ADO Error - really need help urgently

8. Req: Help needed with error message UNEXPECTED ERROR

9. Help needed on Error handler for PostScript

10. I need help with a PS error..

11. JScript Error Help needed!

12. Need Help With Run Time Errors?

 

 
Powered by phpBB® Forum Software