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!

VBScript Arrays

Status
Not open for further replies.

geo0165

Programmer
Dec 23, 2002
2
US
The following code used an array to display the items ordered. The problem is, it only displays the last entry in the array. Please Help Me!!!!

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

Dim i 'as Integer
Dim sTotal
Dim sExtension
Dim sShipCharge
sShipCharge = 15.00
ID1 = Request("sID1")
ID2 = Request("sID2")
%>
<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;#C0C0C0&quot; width=&quot;60&quot;>
<b>
<font face=&quot;Arial&quot;><font size=&quot;2&quot;>Part#</font>
</b>
</td>
<td bgcolor=&quot;#C0C0C0&quot; width=&quot;75&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Item</font>
</b>
</td>
<td bgcolor=&quot;#C0C0C0&quot; width=&quot;299&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Description</font>
</b>
</td>
<td bgcolor=&quot;#C0C0C0&quot; width=&quot;3&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Quantity Ordered</font>
</b>
</td>
<td bgcolor=&quot;#C0C0C0&quot; width=&quot;7&quot;>
<b>
<font size=&quot;2&quot; face=&quot;Arial&quot;>Price</font>
</b>
</td>
</tr>
<%
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;><%=aPartNumber(i)%>&nbsp;</font></td>
<td width=&quot;75&quot;><font size=&quot;2&quot;><%=aItem(i)%>&nbsp;</font></td>
<td width=&quot;299&quot;><font size=&quot;2&quot;><%=aDescription(i)%>&nbsp;</font></td>
<td width=&quot;3&quot; align=&quot;Right&quot;><font size=&quot;2&quot;><%=aQtyOrder(i)%></font></td>
<td width=&quot;7&quot;><font size=&quot;2&quot;><%=FormatCurrency(aPrice(i))%>&nbsp;</font></td>
</tr>
<%
Next 'i
iCount=iCount + 1
sTotal = sTotal + sShipCharge
%>
<tr>
<td width=&quot;60&quot;></td>
<td width=&quot;75&quot;></td>
<td width=&quot;299&quot;></td>
<td width=&quot;3&quot;><font color=&quot;#000080&quot;>Delivery Charge:</font></td>
<td width=&quot;7&quot;> <font size=&quot;2&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 width=&quot;3&quot;><font color=&quot;#000080&quot;>Total:</font></td>
<td width=&quot;7&quot;> <font size=&quot;2&quot;><%=FormatCurrency(sTotal)%>&nbsp;</font></td>
</tr>

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



Public aPartNumber() 'as Array
Public aQtyOrder() 'as Array
Public aPrice() 'as Array
Public aItem() 'as Array
Public 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



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 iCount

Case &quot;CheckOut&quot;
PlaceOrder

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

Case Else 'Item Search
ItemSearch

End Select
%>
End Sub
 
Looks like you should get only the first item because iCount is never set to any value and thus is always 0.
'iCount = 0 here
for i=0 to iCount
'if aPartNumber(i) <> &quot;&quot; then
sExtension = aQtyOrder(i) * aPrice(i)
sTotal = sTotal + sExtension
%>
html stuff
<%
'also, iCount is evaluated ONLY at the start of the loop
Next 'i
'the following does nothing for a For/Next loop that has already been executed
iCount=iCount + 1

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top