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

Populate Array 2

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
0
0
US
I have a list box that contains muliple values and I want to associate a cost with each value. Currently I have the following and it works, But I was wondering if there is a better way of populating the price array.


Price(0 to 5) as currency

Price(0) = 80
Price(1) = 370
Price(2) = 175
Price(3) = 60
Price(4) = 325
Price(5) = 200
 
Hi,

I don't understand.

Why don't you populate the listbox with BOTH cost AND value?
Why use an array at all?

Regards,

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience." darrylles@totalise.co.uk
 
How do you populate the listbox with both a price and array?
 
I am using

With lstCPU
.AddItem "Intel Celeron 1.8 Ghz"
.AddItem "P4-2.8 Ghz/533 Sock 478"
.AddItem "Athlon XP 2400+ (2Ghz)"
.AddItem "Intel P4-1.5Ghz/400 Socket 478"
.AddItem "Athkin XP 1500+ (1.33Ghz)"
.AddItem "Athlon XP 2700+ (2.167Ghz)"
End With
 
If you do need the array then have a look at the Array function in the VB 6 help
 
Hi,

Use the .ItemData array to store the associated values:

---------------------------------------
With lstCPU
.AddItem "Intel Celeron 1.8 Ghz"
.ItemData(0) = 80
.AddItem "P4-2.8 Ghz/533 Sock 478"
.ItemData(1) = 370
.AddItem "Athlon XP 2400+ (2Ghz)"
.ItemData(2) = 175
.AddItem "Intel P4-1.5Ghz/400 Socket 478"
.ItemData(3) = 60
.AddItem "Athkin XP 1500+ (1.33Ghz)"
.ItemData(4) = 325
.AddItem "Athlon XP 2700+ (2.167Ghz)"
.ItemData(5) = 200
End With
---------------------------------------
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Dim Price as Variant

Price = Array(80, 370, 175, 60, 325, 200)

Nice for building nested arrays as well ...

Dim ItemInfo as Variant

ItemInfo = Array (_
Array("Item 1", 80, "5 in stock") _
, Array("Item 2", 370, "none in stock") _
)

ItemInfo(0)(1) = 80
ItemInfo(1)(2) = "none in stock"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top