p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asptoday_discuss thread: Finding the number of elements in an array.


Message #1 by "Mark Berry" <mbfromit@h...> on Thu, 13 Sep 2001 04:33:59
I am trying to create a shopping cart.  I used the dictionary object 

to store the Item and Qty.  I want to loop through the dicObject and load 

the results into an array.  The problem is I don't know how many items 

will be in the dicObject so I can set a fized lenght for the array.  But 

if I set the length of the array to something stupid like 500.  I get 495+ 

empty records in my database when I dump the array back to it.  I have 

found comments on UBound but that doesnt seem to help me.  Any ideas on 

how to solve this problem?



thanks!
Message #2 by "Rich McQuaid" <remcq@m...> on Thu, 13 Sep 2001 07:43:10 -0400
Mark,



The dictionary object has a count property that you can use to set the size

of your array.



Dim arrayName(dicObject.count -1)



I think you need to subtract one to avoid having an extra empty element .

The array is zero based and the count property is not.





Rich







----- Original Message -----

From: "Mark Berry" <mbfromit@h...>

To: "ASPToday Discuss" <asptoday_discuss@p...>

Sent: Thursday, September 13, 2001 4:33 AM

Subject: [asptoday_discuss] Finding the number of elements in an array.





> I am trying to create a shopping cart.  I used the dictionary object

> to store the Item and Qty.  I want to loop through the dicObject and load

> the results into an array.  The problem is I don't know how many items

> will be in the dicObject so I can set a fized lenght for the array.  But

> if I set the length of the array to something stupid like 500.  I get 495+

> empty records in my database when I dump the array back to it.  I have

> found comments on UBound but that doesnt seem to help me.  Any ideas on

> how to solve this problem?

>

> thanks!

>



Message #3 by "Mark Berry" <mbfromit@h...> on Fri, 14 Sep 2001 03:45:09
That did the trick.



Thanks!



> Mark,

> 

> The dictionary object has a count property that you can use to set the 

size

> of your array.

> 

> Dim arrayName(dicObject.count -1)

> 

> I think you need to subtract one to avoid having an extra empty element .

> The array is zero based and the count property is not.

> 

> 

> Rich

> 

> 

> 

> ----- Original Message -----

> From: "Mark Berry" <mbfromit@h...>

> To: "ASPToday Discuss" <asptoday_discuss@p...>

> Sent: Thursday, September 13, 2001 4:33 AM

> Subject: [asptoday_discuss] Finding the number of elements in an array.

> 

> 

> > I am trying to create a shopping cart.  I used the dictionary object

> > to store the Item and Qty.  I want to loop through the dicObject and 

load

> > the results into an array.  The problem is I don't know how many items

> > will be in the dicObject so I can set a fized lenght for the array.  

But

> > if I set the length of the array to something stupid like 500.  I get 

495+

> > empty records in my database when I dump the array back to it.  I have

> > found comments on UBound but that doesnt seem to help me.  Any ideas on

> > how to solve this problem?

> >

> > thanks!

> >

> 


  Return to Index