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

Battle with Arrays

Status
Not open for further replies.

geo0165

Programmer
Dec 23, 2002
2
US
The below script adds items to an array, the problem is only the last entry will display when calling the subroutine ShowOrder. Please help me with this battle

<% Option Explicit
%>

<style fprolloverstyle>A:hover {color: #0000FF; text-decoration: overline underline}
</style>
<% 'Order.asp
Sub AddItem(PartNumber, Item, Description, Price, Quantity, iCount)
'ReDim Preserve aPartNumber(iCount)
'aPartNumber(iCount) = PartNumber
'ReDim Preserve aItem(iCount)
'aItem(iCount) = Item
'ReDim Preserve aDescription(iCount)
'aDescription(iCount) = Description
'ReDim Preserve aPrice(iCount)
'aPrice(iCount) = Price
'ReDim Preserve aQtyOrder(iCount)
'aQtyOrder(iCount) = Quantity
'ShowOrder aPartNumber, aItem, aDescription, aPrice, aQtyOrder
End Sub

'**************************************
Sub ShowOrder

'Dim i 'as Integer
Dim sTotal
Dim sExtension
Dim sShipCharge
Dim var1
sShipCharge = 15.00
ID1 = Request(&quot;sID1&quot;)
ID2 = Request(&quot;sID2&quot;)

%>
<body vlink=&quot;#0000FF&quot; alink=&quot;#0000FF&quot;>

<table border=&quot;1&quot; cellpadding=&quot;2&quot; style=&quot;border-left-color: #0000FF; border-top-color: #0000FF&quot; width=&quot;100%&quot; bordercolorlight=&quot;#FF0000&quot; bordercolordark=&quot;#0000FF&quot;>
<tr>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;60&quot;>
<font face=&quot;Arial&quot; color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot;>Part#</font>
</b>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;75&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Item</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;299&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Description</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;3&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Quantity Ordered</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;7&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot; color=&quot;#000080&quot;>Price</font>
</b>
</td>
</tr>
<form name=&quot;AddItem&quot;>
<%
stotal = 0
for i=0 to iCount
'if aPartNumber(i) <> &quot;&quot; then
sExtension = aQtyOrder(i) * aPrice(i)
sTotal = sTotal + sExtension
%>
<tr>
<td width=&quot;60&quot;><font size=&quot;2&quot; color=&quot;#000080&quot;><%=aPartNumber(i)%>&nbsp;</font></td>
<td width=&quot;75&quot;><font size=&quot;2&quot; color=&quot;#000080&quot;><%=aItem(i)%>&nbsp;</font></td>
<td width=&quot;299&quot;><font size=&quot;2&quot; color=&quot;#000080&quot;><%=aDescription(i)%>&nbsp;</font></td>
<td width=&quot;3&quot; align=&quot;Right&quot;><font size=&quot;2&quot; color=&quot;#000080&quot;><%=aQtyOrder(i)%></font></td>
<td width=&quot;7&quot;><font size=&quot;2&quot; color=&quot;#000080&quot;><%=FormatCurrency(aPrice(i))%>&nbsp;</font></td>
</tr>
<input type=&quot;hidden&quot; name=part<%=i%> value=<%=aPartNumber(i)%>>
<input type=&quot;hidden&quot; name=item<%=i%> value=<%=aItem(i)%>>
<input type=&quot;hidden&quot; name=description<%=i%> value=<%=aDescription(i)%>>
<input type=&quot;hidden&quot; name=qty<%=i%> value=<%=aQtyOrder(i)%>>
<input type=&quot;hidden&quot; name=price<%=i%> value=<%=aPrice(i)%>>

<%
'end if
Next 'i
iCount=iCount + 1
sTotal = sTotal + sShipCharge
%>
</form>
<tr>
<td width=&quot;60&quot;></td>
<td width=&quot;75&quot;></td>
<td width=&quot;299&quot;></td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;3&quot;><b><font color=&quot;#000080&quot;>Delivery Charge:</font></b></td>
<td width=&quot;7&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;><%=FormatCurrency(sShipCharge)%>&nbsp;</font></td>
</tr>
<tr>
<td width=&quot;60&quot;><a href=&quot;Order.asp?action=ShowCatelog&Count=<%=iCount%>&sID1=<%=ID1%>&sID2=<%=ID2%>&quot;>Previous</a></td>
<td width=&quot;75&quot;><a href=&quot;Order.asp?action=Nothing&Count=<%=iCount%>&quot;>Item Search</a></td>
<td width=&quot;299&quot;></td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;3&quot;><b><font color=&quot;#000080&quot;>Total:</font></b></td>
<td width=&quot;7&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;><%=FormatCurrency(sTotal)%>&nbsp;</font></td>
</tr>

<form name=&quot;ShowOrder1&quot;>
<input type=&quot;hidden&quot; name=&quot;sID1&quot; value=<%=ID1%>>
<input type=&quot;hidden&quot; name=&quot;sID2&quot; value=<%=ID2%>>
</form>
<%
End Sub


' *******Item Search
Sub ItemSearch()

Dim objDC, objRS, objRS2

iCount = CInt(Request.QueryString(&quot;Count&quot;))

' Create and establish data connection
Set objDC = Server.CreateObject(&quot;ADODB.Connection&quot;)
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30

'Use this line to use Access
objDC.Open &quot;DSN=JerryLabant&quot;

' Create recordset and retrieve values using the open connection
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set objRS2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)

objRS.Open &quot;Makes&quot;, objDC, 0, 1
objRS2.Open &quot;Categories&quot;, objDC, 0, 1
' Loop through recordset and display results

%>
<form name=&quot;form1&quot; action=&quot;Order.asp?action=ShowCatelog&Count=<%=iCount%>&quot; method=&quot;Post&quot;>

<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;50%&quot; nowrap>
<p align=&quot;Center&quot;><font color=&quot;#000080&quot;>Select Vehicle Make</font>:&nbsp;
<select name=&quot;sID1&quot; style=&quot;color: #000080&quot;>
<option value=&quot;0&quot;>*ALL</option>
<%
' Continue until we get to the end of the recordset.
Do While Not objRS.EOF
' For each record we create a option tag and set it's value to the employee id
' The text we set to the employees first name combined with a space and then their last name
%>
<option value=&quot;<%= objRS.Fields(&quot;MNumber&quot;) %>&quot;><%= objRS.Fields(&quot;MDescription&quot;) %></option>

<%
' Get next record
objRS.MoveNext
Loop
%>

</select>
</p>
</td>
<td width=&quot;50%&quot; nowrap>
<p align=&quot;Center&quot;>&nbsp;&nbsp;&nbsp;&nbsp; <font color=&quot;#000080&quot;>Select Category:</font>&nbsp;

<select name=&quot;sID2&quot; style=&quot;color: #000080&quot;>
<option value=&quot;0&quot;>*ALL</option>

<%
' Continue until we get to the end of the recordset.
Do While Not objRS2.EOF
' For each record we create a option tag and set it's value to the employee id
' The text we set to the employees first name combined with a space and then their last name
%>
<option value=&quot;<%= objRS2.Fields(&quot;CNumber&quot;) %>&quot;><%= objRS2.Fields(&quot;CDescription&quot;) %></option>

<%
' Get next record
objRS2.MoveNext
Loop
%>
</select>
</p>
</td>
</tr>
</table>
<p align=&quot;Center&quot;>
<input type=&quot;Submit&quot; value=&quot;Search&quot;>
</p>
<input type=&quot;hidden&quot; name=&quot;Count&quot; value=<%=iCount%>>
</form>

<%
End Sub

Sub ShowCatelog(ID1, ID2)

Dim boolCanRun
Dim objConn
Dim objRS
Dim strSQL
Dim strFilter1
Dim strFilter2
Dim intRecordCount
Dim color
Dim var1
boolCanRun = true
color = &quot;#CCCCCC&quot;
strFilter1 = ID1
strFilter2 = ID2
iCount = CInt(Request.QueryString(&quot;Count&quot;))

If boolCanRun then

set objConn = Server.createObject(&quot;ADODB.Connection&quot;)

objConn.Open &quot;DSN=JerryLabant&quot;

if strFilter1 = 0 AND strFilter2 = 0 then
set objRS = objConn.Execute(&quot;select * from ItemMaster Order By MakeNumber&quot;)
end if

if strFilter1 = 0 AND strFilter2 <> 0 then
set objRS = objConn.Execute(&quot;select * from ItemMaster where CategoryNumber =&quot; & strFilter2 &&quot; Order By MakeNumber&quot;)
end if

if strFilter1 <> 0 AND strFilter2 = 0 then
set objRS = objConn.Execute(&quot;select * from ItemMaster where MakeNumber =&quot; & strFilter1 &&quot; Order By MakeNumber&quot;)
end if

if strFilter1 <> 0 AND strFilter2 <> 0 then
set objRS = objConn.Execute(&quot;select * from ItemMaster where MakeNumber =&quot; & strFilter1 &&quot; AND CategoryNumber =&quot; & strFilter2 &&quot; &quot;)
end if

'Set our counter to zero
intRecordCount = 0

%>

<table border=&quot;1&quot; cellpadding=&quot;2&quot; style=&quot;border-left-color: #0000FF; border-top-color: #0000FF&quot; width=&quot;100%&quot; bordercolorlight=&quot;#FF0000&quot; bordercolordark=&quot;#0000FF&quot;>
<tr>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;60&quot;>
<font face=&quot;Arial&quot; color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot;>Part#</font>
</b>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;75&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Item</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;299&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Description</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;3&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Quantity</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;7&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Price</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;70&quot;>
<font color=&quot;#000080&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Image</font>
</b>
</font>
</td>
<td bgcolor=&quot;#F5F5F5&quot; width=&quot;76&quot;>
<b>
<font color=&quot;#000080&quot;>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Add To Cart</font> </font>
</tr>
<%
Do while not objRS.EOF
if color = &quot;#FFFFFF&quot; then
color = &quot;#F5F5F5&quot;
else
color = &quot;#FFFFFF&quot;
end if
%>
<form name=&quot;form2&quot; action=&quot;order.asp?action=add&Count=<%=iCount%>&quot; method=&quot;post&quot;>
<tr>
<td bgcolor=<%=color%> width=&quot;60&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;><%=objRS(&quot;PartNumber&quot;)%>&nbsp;</font></td>
<td bgcolor=<%=color%> width=&quot;75&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;><%=objRS(&quot;Item&quot;)%>&nbsp;</font></td>
<td bgcolor=<%=color%> width=&quot;299&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;><%=objRS(&quot;Description&quot;)%>&nbsp;</font></td>
<td bgcolor=<%=color%> width=&quot;3&quot;>
<font size=&quot;2&quot; color=&quot;#000080&quot;>
<input type=&quot;text&quot; name=&quot;txtQty&quot; value=&quot;<%=objRS(&quot;Quantity&quot;)%>&quot; size=&quot;2&quot; style=&quot;color: #000080&quot;></font></td>
<td bgcolor=<%=color%> width=&quot;7&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;><%=FormatCurrency(objRS(&quot;Price&quot;))%>&nbsp;</font></td>
<% if objRS(&quot;Image&quot;) = &quot;&quot; then %>
<td bgcolor=<%=color%> width=&quot;70&quot;>
<p align=&quot;center&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;>No</font></td>
<% else %>
<td bgcolor=<%=color%> width=&quot;76&quot;>
<p align=&quot;center&quot;> <font size=&quot;2&quot; color=&quot;#000080&quot;>
<a href=&quot;images/<%=objRS(&quot;Image&quot;)%>&quot;>Yes</a></font></td>
<% end if %>
<td bgcolor=<%=color%> width=&quot;76&quot;><font size=&quot;2&quot; color=&quot;#000080&quot;>
<input type=&quot;Submit&quot; Value=&quot;Add Item&quot;>
</td>
</tr>
<input type=&quot;hidden&quot; name=&quot;txtPart&quot; Value=&quot;<%=objRS(&quot;PartNumber&quot;)%>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtItem&quot; Value=&quot;<%=objRS(&quot;Item&quot;)%>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtDescription&quot; Value=&quot;<%=objRS(&quot;Description&quot;)%>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtPrice&quot; Value=&quot;<%=objRS(&quot;Price&quot;)%>&quot;>
<input type=&quot;hidden&quot; name=&quot;Count&quot; Value=<%=iCount%>>
<input type=&quot;hidden&quot; name=&quot;sID1&quot; value=<%=ID1%>>
<input type=&quot;hidden&quot; name=&quot;sID2&quot; value=<%=ID2%>>
</form>
<%
objRS.MoveNext
intRecordCount = intRecordCount + 1
loop
%>
</table>
<%

if intRecordCount = 0 then
%>

<p>
<font face=&quot;Arial&quot; color=&quot;#000080&quot;>
Your Search did not return any products. Please try again.
</font>
</p>

<%
else
%>
<p>
<font face=&quot;Arial&quot;>
<%=intRecordCount%> <font color=&quot;#000080&quot;>record(s) were found </font>
</p>
<%
end if

objRS.close
objConn.close

set objRS = nothing
set objConn = nothing

end if
End Sub
%>
<p style=&quot;margin-top: 0; margin-bottom: 1&quot;><img border=&quot;0&quot; src=&quot;images/LMWBanner1.png&quot; width=&quot;468&quot; height=&quot;60&quot;></p>
<hr color=&quot;#0000FF&quot;>
</table>

</font>

</a>

<%
'Runtime Script
Dim aPartNumber() 'as Array
Dim aQtyOrder() 'as Array
Dim aPrice() 'as Array
Dim aItem() 'as Array
Dim aDescription() 'as Array
Dim sAction 'as String
Dim iCount 'as Integer
Dim PartNumber 'as String
Dim Item 'as String
Dim Description 'as String
Dim Price 'as Integer
Dim Quantity 'as Integer
Dim ID1
Dim ID2
Dim OrderNumber 'as Integer
Dim i
sAction = Request(&quot;action&quot;)
PartNumber = Request(&quot;txtPart&quot;)
Item = Request(&quot;txtItem&quot;)
Description = Request(&quot;txtDescription&quot;)
Price = Request(&quot;txtPrice&quot;)
Quantity = Request(&quot;txtQty&quot;)
iCount = CInt(Request.QueryString(&quot;Count&quot;))
ID1 = Request(&quot;sID1&quot;)
ID2 = Request(&quot;sID2&quot;)

Select Case sAction
Case &quot;add&quot;

ReDim Preserve aPartNumber(iCount)
aPartNumber(iCount) = PartNumber
ReDim Preserve aItem(iCount)
aItem(iCount) = Item
ReDim Preserve aDescription(iCount)
aDescription(iCount) = Description
ReDim Preserve aPrice(iCount)
aPrice(iCount) = Price
ReDim Preserve aQtyOrder(iCount)
aQtyOrder(iCount) = Quantity

'AddItem PartNumber, Item, Description, Price, Quantity, iCount
'iCount = iCount + 1
ShowOrder

Case &quot;del&quot;
DelItem PartNumber, iCount
'ShowOrder

Case &quot;ShowOrder&quot;
ShowOrder

Case &quot;CheckOut&quot;
PlaceOrder

Case &quot;ShowCatelog&quot;
ShowCatelog ID1, ID2

Case Else 'Item Search
ItemSearch

End Select
%>
 
You've got over 400 lines of code here.
[ol]
[li]Where is the error occuring (I can't duplicate your databases and DSNs)
[li]Put your code loading the arrays before your code displaying them (it looks like it shouldn't matter, but it might...)
[li]Is AddItem() supposed to be commented out entirely?
[li]In showOrder, iCount is retreived from a querystring, and is not based on the size of the array at all (better practice is to use the uBound() of the array?
[li]Instead of so many arrays, have you considered a 2-dimensional array?
[/ol]
Get the Best Answers! faq333-2924
Merry Christmas!
mikewolf@tst-us.com
[angel][santa][elf][reindeer][santa2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top