1
   

Sorting INformation in VBScript Arrays

 
 
Reply Tue 1 Mar, 2005 11:44 am
HI Everyone,

I have this problem with VBScript Arrays I have been working on for the last week and feel like I'm standing still. I have probably been very colse to a solution a number of times (i think) but just cant get there and would appreciate any help from anyone.

I have an html form page that dynamically displays product info for various products. IF a user enters a quantity in any product quantity box(s) the next page should display all the associated product info related with that quantity box(s) (price, oem, color, quantity).

the product info fields are all hidden form fields, except for quantity field.
They are named like this:

PRODUCT 1 INFO:
quantity_1
oem_1
price_1
color_1

PRODUCT 2 INFO:
quantity_2
oem_2
.....

After the user clicks the 'calculate order' submit button to go to the next page that is supposed to display all relavent info, the form info goes into a 2D array, the first dimension holds the form field name (e.g. price_1)
and the second Dimension holds the form field value (e.g. $4.99).

I can get the correct array values to display on the page, showing all the product information (quantity, oem, price, color) for all the products selected but my problem is that I cannot get the product info to display in a specific order. I want them to display in this order (OEM, COLOR, PRICE, QUANTITY).

Becuase the form values are always ordered differently I need to do some clever looping and if statements to order the info the way I want.
THis is what I cant seem to figure out.

BELOW WOULD BE THE ORDER THAT THE PRODUCT INFO COMES IN WHICH IS STORED IN AN ARRAY called 'CARTS_combined':
oem_1 = C4836AN
price_1 = $34.95
oem_2 = C4837AN
color_1 = Cyan
cart_quantity_1 = 7
cart_quantity_2 = 4
price_2 = $34.95
color_2 = Magenta


BELOW is the code Im using to try and sort the CARTS_combined Array info into the correct order, I have an if statement inside a FOR loop inside a DO UNTIL loop:

'-------------------------------------------------------------------------------------
Response.write TRYING TO PUT THE INFO IN RIGHT ORDER<BR>"

Response.Write("<table border=2>")
Response.Write("<tr><td><B>Row</B></td><td><B>oem</B></td>")
Response.Write("<td><B>price</B></td><td><B>color</B></td>")
Response.write ("<td><B>quantity</B></td></tr>")
Response.Write("</table>")


'WRITE CARTS_combined TABLE WITH ALL INFO

inner_counter = 1
inner_inner_counter = 1
array_count = 1
order_count = 1

Response.Write("<table border=2>")

new_count = 1

DO UNTIL inner_counter = UBOUND(CARTS_combined, 2)

For i = 0 to UBound(CARTS_combined, 2)

IF (LEFT(CARTS_combined(0, i), 5)) = ("oem_" & inner_counter) AND order_count = 1 THEN

Response.Write("<tr><td>#" & i & "</td>")
Response.Write("<td>" & CARTS_combined(0,i) & " </td>")
Response.Write("<td>" & CARTS_combined(1,i) & " </td>")
Response.Write("<td>order_count = " & order_count & " </td>")
Response.Write("<td>inner_counter = " & inner_counter & " </td></tr>")
order_count = order_count + 1
ELSE IF (LEFT(CARTS_combined(0, i), 7)) = ("price_" & inner_counter) AND order_count = 2 THEN

Response.Write("<tr><td>#" & i & "</td>")
Response.Write("<td>" & CARTS_combined(0,i) & " </td>")
Response.Write("<td>" & CARTS_combined(1,i) & " </td>")
Response.Write("<td>order_count = " & order_count & " </td>")
Response.Write("<td>inner_counter = " & inner_counter & " </td></tr>")
order_count = order_count + 1

ELSE IF (LEFT(CARTS_combined(0, i), 7)) = ("color_" & inner_counter) AND order_count = 3 THEN
Response.Write("<tr><td>#" & i & "</td>")
Response.Write("<td>" & CARTS_combined(0,i) & " </td>")
Response.Write("<td>" & CARTS_combined(1,i) & " </td>")
Response.Write("<td>order_count = " & order_count & " </td>")
Response.Write("<td>inner_counter = " & inner_counter & " </td></tr>")
order_count = order_count + 1
ELSE IF (LEFT(CARTS_combined(0, i), 15)) = ("cart_quantity_" & inner_counter) AND order_count = 4 THEN
Response.Write("<tr><td>#" & i & "</td>")
Response.Write("<td>" & CARTS_combined(0,i) & " </td>")
Response.Write("<td>" & CARTS_combined(1,i) & " </td>")
Response.Write("<td>order_count = " & order_count & " </td>")
Response.Write("<td>inner_counter = " & inner_counter & " </td></tr>")
order_count = order_count + 1

END IF
END IF
END IF
END IF

NEXT

inner_counter = inner_counter + 1
order_count = 1

LOOP
'---------------------------------------------------------------------------------

I know that what is happening is that because the '_2' product info is in a different order then what I want. (ie. cart_quantity_2) my 'order_count'
criteria makes my if statement miss the 'cart_quantity_2' but without the order_count I cant get the product info in the proper order that I want
ie. (oem, price, color, quantity) - This is my problem.

Please anyone help.

Also, If this problem needs elaborating or clarification please let me know.

Thank you all.

Andrew
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 769 • Replies: 0
No top replies

 
 

Related Topics

Webdevelopment and hosting - Question by harisit2005
Showing an Ico File - Discussion by Brandon9000
how to earn money in internet - Discussion by rizwanaraj
The version 10 bug. Worse then Y2K! - Discussion by Nick Ashley
CSS Border style colors - Question by meesa
There is no Wisdom in Crowds - Discussion by ebrown p
THANK YOU CRAVEN AND NICK!!! - Discussion by dagmaraka
I'm the developer - Discussion by Nick Ashley
 
  1. Forums
  2. » Sorting INformation in VBScript Arrays
Copyright © 2025 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 01/18/2025 at 12:18:16