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

two dimensional array question

Status
Not open for further replies.

Bob2

Programmer
Jul 3, 2000
228
SE
Hi


I could use some help in cretaing a two dimensional array.
I have a while statement that loops through a recordset The recordset consits of article numbers and how many items a user have order of that specific article. So I would like to create an array that would hold the article number and how many of that article the user have ordered.

Dim myArray()
Dim iCounter
Redim myArray(intTotalRecords)

iCounter = 0


While (NOT rs_Order.EOF))
' here should the array gets its values from
' (rs_Order.Fields.Item("ArticleNo").Value)
' and
' (rs_Order.Fields.Item("Qty").Value)
rs_Order.MoveNext()
iCounter = iCounter + 1
Wend


Could someone please show me how I can do this and then loop through the array and display the article number and the corresponding quantity?



Best Regards


M

 
Better IMO would be to use a dictionary object where the key is the article and the value is the count. Then all your iteration methods are created for you.
 
Hi


I'm not that familiar with the dictionar object, could you show me an example of this?

Regards

M
 
Something like this:
Code:
Dim myDict


Set myDict = CreateObject("Scripting.Dictionary")

While (NOT rs_Order.EOF))
    ' here should the array gets its values from
    myDict.Add rs_Order.Fields.Item("ArticleNo").Value, _
               rs_Order.Fields.Item("Qty").Value
    rs_Order.MoveNext()
Wend 

For Each myKey In myDict.Keys()
    WScript.Echo "Article No: " & myKey & " Qty: " & myDict.Item(myKey)
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top