Home > ASP Development > Using Arrays

Using Arrays



Hi



Can someone please assist



I have dimed an array as per the code below and in the body of the page I then build the array. However when I try and retrieve the contents I get nothing




Code:



<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<%
Dim theProductCode(20), theProductName(20),theproductSize(20)

if request("submitted") = "1" then


for i = 0 to ubound(theproductcode)
response.write "theproduct is"&theproductCode(i)
response.write "theproductname is "&theproductname(i)
next


in the body section

while not rs.eof
thesizegrid = replace(rs("sales_code"),"@","")
theproductcode(x) = rs("stock_namekey")
theproductname(x) = rs("description_0")


%><td><%response.write rs("stock_namekey")%> </td>
<td><%response.write rs("description_0")%></td>






Hope the above extract makes sense



Thanks

Moris

    
Guest


where is the code that builds the array and puts the values in?

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by markoc
where is the code that builds the array and puts the values in?




That is the code in red ( in the <body> of the page)




Code:



in the body section

while not rs.eof
thesizegrid = replace(rs("sales_code"),"@","")
theproductcode(x) = rs("stock_namekey")
theproductname(x) = rs("description_0")



Was this answer helpful ? Yes No   
Guest


ok well do you have x like this:




Code:



DIM Dim theProductCode(20), theProductName(20),theproductSize(20), x
x = 0
do while not rs.eof
thesizegrid = replace(rs("sales_code"),"@","")
theproductcode(x) = rs("stock_namekey")
theproductname(x) = rs("description_0")
x = x + 1
rs.MoveNext
loop






and this code has to be before the following:




Code:



for i = 0 to 19
Response.Write "theproduct is" & theproductCode(i) & " - "
Response.Write "theproductname is " & theproductname(i)
next



Was this answer helpful ? Yes No   
Guest


very true, and in addition you better check that you don't have too many

records otherwise you'll get error... add such line:


Code:


If x>20 Then Exit While




if you don't know how many records there can be, use dynamic array or

even simple string that you can later Split.

Was this answer helpful ? Yes No   
Guest


Hi



Thanks for your assistance.



Here is the entire code. When I do the writing of the array where it is in the code I get nothing. If I do it within the <body> it works ok



Moris










Code:


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
Dim theProductCode(20), theProductName(20),theproductSize(20)%>
<html>


<%


if request("submitted") = "1" then


for i = 0 to ubound(theproductcode)
response.write "theproduct is"&theproductCode(i)
response.write "theproductname is "&theproductname(i)
next
for i = 0 to session("noOfProducts")

response.write theproductName(i)
if request("quantity("&i&")") > 0 then
response.write request("quantity("&i&")")

end if
next


end if%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<%function getsize(thegrid, thesizetoget)


mysql = "select * from stock_grid_desc WHERE grid_namekey = '" & thegrid & "'"
myDSN="DSN=tcash;uid=sysadmin;pwd=sysadmin"
set consize=server.createobject("adodb.connection")
consize.open myDSN
set rssize=consize.execute(mySQL)
if not rssize.eof then
getsize = rssize("size_desc_"&thesizetoget&"")


end if
rssize.close
set rssize = nothing
set consixe = nothing
end function%>
<body>

<%
session("refundOrderNo") = "L119000007"
mySQL="SELECT reference,debtor_namekey,stock_namekey,description _0,stock_classification_0,stock_classification_2,c ategory,sales_code,"
mysql = mysql&"classification_0,classification_1,classification_2 ,transaction_date,"
mysql = mysql&"quantity_sold_00,quantity_sold_01,quantity_sold_02 ,quantity_sold_03,quantity_sold_04,"
mysql = mysql&"quantity_sold_05,quantity_sold_06,quantity_sold_07 ,quantity_sold_08,quantity_sold_09,"
mysql = mysql&"quantity_sold_10,quantity_sold_11,quantity_sold_12 ,quantity_sold_13,quantity_sold_14,"
mysql = mysql&"quantity_sold_15,quantity_sold_16,quantity_sold_17 ,quantity_sold_18,quantity_sold_19,"
mysql = mysql&"our_order_number,Unit_Sale_Value_incTax,Unit_Sale_ Tax,diary_namekey,transaction_date"
mysql = mysql&" FROM sales_history"
mysql = mysql&" WHERE reference = '"&session("RefundOrderNo")&"'"
myDSN="DSN=tcash;uid=sysadmin;pwd=sysadmin"
set con=server.createobject("adodb.connection")
con.open myDSN
set rs=con.execute(mySQL)
if not rs.eof then

%>
<form action="" method="post">
<table width="675" height="144" border="8" align="center" cellpadding="10" cellspacing="0" bordercolor="#000000" bgcolor="#FFFFFF">
<tr>
<td colspan="6" align="center"><img src="Images/tarocash%20logo.jpg"></td>

</tr>
<tr>
<td colspan="6">
<%
response.write "<br>"& session("title")&" "&session("cfname")&" "&session("clname")&" "&rs("diary_namekey")
response.write "<br>"& session("caddress1")
if session("caddress2") <> "" then
response.write "<br>"& session("caddress2")
end if
response.write "<br>"& session("caddress3")&" "& session("caddress4")&" "&session("cpostcode")

response.write "<br> Invoice Number: "& rs("reference")

response.write "&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;"
Response.write "Order Number: " &rs("Our_Order_Number")
response.write "&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;"
response.write "Date: "&rs("transaction_date")
response.write "<br><br><br>You Purchased the following items: <br><br> Please enter the quantity for the item(s) being returned" %>

</td>
</tr>
<tr bgcolor="#FFFFCC">
<td width="93">Product Code</td>
<Td width="205">Product Description</Td>
<TD>Price</TD>
<td>Size</td>
<td>Quantity</td>
<td>Quantity<br> Returned</td>
</tr>
<tr>
<%
HasPreviousQuantity = false


x= 0
while not rs.eof
thesizegrid = replace(rs("sales_code"),"@","")
theproductcode(x) = rs("stock_namekey")
theproductname(x) = rs("description_0")

%><td><%response.write rs("stock_namekey")%> </td>
<td><%response.write rs("description_0")%></td>
<td width="31"><%response.write formatcurrency(rs("unit_sale_value_incTax"),2)%></td>
<%for i = 0 to 9
if rs("quantity_sold_0"&i&"") <> 0 then

if HasPreviousQuantity = false then
thesizetoget = "0"&i %>
<td width="37"> <%response.write getsize(thesizegrid,thesizetoget) %></td>

<td width="51"><%response.write rs("quantity_sold_0"&i&"")
HasPreviousQuantity = true%>
<td><input name="quantity(<%=x%>)" type="text" class="textbox" id="quantity(<%=x%>)" value="0" size="3" maxlength="6"></td>
else%>
<%
theproductcode(x) = rs("stock_namekey")
thesizetoget = "0"&i %>
<td width="37"> <%response.write getsize(thesizegrid,thesizetoget) %></td>
<td width="51"><%response.write rs("quantity_sold_0"&i&"")%></td>
</tr>
<tr>
<td><%response.write rs("stock_namekey")%> </td>
<td><%response.write rs("description_0")%></td>
<td width="31"><%response.write formatcurrency(rs("unit_sale_value_incTax"),2)%></td>
<td><input name="quantity(<%=x%>)" type="text" class="textbox" id="quantity(<%=x%>)" value="0" size="3" maxlength="6"></td>


<% end if

end if
next
for i = 10 to 19
if rs("quantity_sold_"&i&"") <> 0 then
if HasPreviousQuantity = false then
thesizetoget = i %>
<td width="70"><% response.write getsize(thesizegrid,thesizetoget) %></td>
<td width="18"><%response.write rs("quantity_sold_"&i&"")%></td>
<td><input name="quantity(<%=x%>)" type="text" class="textbox" id="quantity(<%=x%>)" value="0" size="3" maxlength="6"></td>
<%HasPreviousQuantity = true%>
<%else%>
<%

thesizetoget = i %>
<td width="37"><% response.write getsize(thesizegrid,thesizetoget) %></td>
<td width="51"><%response.write rs("quantity_sold_"&i&"")%></td>
</tr>
<tr>
<td><%response.write rs("stock_namekey")%> </td>
<td><%response.write rs("description_0")%></td>
<td width="31"><%response.write formatcurrency(rs("unit_sale_value_incTax"),2)%></td>
<td><input name="quantity(<%=x%>)" type="text" class="textbox" id="quantity(<%=x%>)" value="0" size="3" maxlength="6"></td>
<% end if %>
<%
end if
next

%>


</tr>
<%
rs.movenext
x = x+1
haspreviousquantity = false

wend
session("noOfProducts") = x

else
response.write "Invoice details Not found for "&session("refundorderno")

end if
rs.close
set rs = nothing
set con = nothing
%>
</tr>
<tr>
<td align="center" colspan="6" height="41"><input name="Submit" type="submit" value="NEXT>>">
<input name="Submitted" type="hidden" value="1">
</td>
</tr>
</table>
</form>
</body>
</html>



Was this answer helpful ? Yes No   
Guest


that's because you're writing it before you populate the array.

move the code where you write the array items to the bottom

of the page and you'll see it.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved