# Thread: Using Data from arrays

1. ## Using Data from arrays

Hi guys , I'm not that clued up on array's ,

I'm extracting some data from a database which is in array format.

Q1
If I want to use this in asp as an array do i need to do anything to tell it that it is an array and not just text that i'm displaying from my recordset.

Q2
Once I have this in a variable which asp knows is an array I want to do the following ;

I have one number field (product quantity), I then have price breaks in an array e.g.

10;99;199;9999999

I then have a second array for what the product price is at each price break

e.g.

1.12; 0.99; 0.49; 0.30

I then want to display the right price for each product line ,

e.g. first line quantity is 5 , second line quantity is 30

so I want to display price for line one as 5 x 1.12 and line two as 30 x 0.99

Can anyone help me or point me in the direction of a good resource for understanding how to use array's in a bit more detail

Andy

2. OK so putting information into an array from a recordset pretty simple.

I'm using

Code:
`PriceBreakArray = split(rsDailyPurchaseLines("qtybrk") ,";")`
Then for my second question on how to determine which position in the array the price break falls under.

The array data for the price break look something like this

50;999999;0;0;0;0;0;0

For my first line the quantity is 300 so i would want the position to be returned as 1 (as 0 would be for a quantity of 50 or below).

This is the for next loop i'm trying to get to do this, so far no joy

Code:
```For n=0 to ubound(PriceBreakArray)

If CLng(rsDailyPurchaseLines("stkqtyord")) <= PriceBreakArray(n) Then
PositionInArray = n
exit for

end if

next```
can anyone spot what i'm doing wrong ?

cheers

Andy

3. If you're using an ado recordset you might take a look at using the getrows() method which automatically builds an array from the recordset.

4. Code:
`If CLng(rsDailyPurchaseLines("stkqtyord")) <= CLng(PriceBreakArray(n)) Then`
???

i.e. cast both sides of the If clause to the same units? Might work.

However (if it is a possibility) I would refactor the database to normalise it, to have a Qty2Prices table with fields like ...

ProdID | Qty | Price
12345 | 1 | 6.99
12345 | 10 | 5.99
12345 | 100 | 4.99
12345 | 1000 | 3.99

... Then you can get at the price per quantity straight from a SQL command, such as ...

Code:
`sSQL = "SELECT TOP 1 Price FROM Qty2Prices WHERE Qty >= " & qtyord & " AND ProdID = " & prodid`

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•