Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2003, 10:30 AM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Storing a unknown number of strings to an Array

I have this system where a flexible number of Queries are being sent to my .asp page.

I think the best way of storing the queries will be to an Array but I can't figure ut a nice way of doing this ..

Later on down the script, is there a nice way of asking the array if it contain a certain value?

/Paw
 
Old November 21st, 2003, 10:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sounds like you need to read up on the Scripting.Dictionary object, particularly the Add and Exists methods.
 
Old November 21st, 2003, 10:52 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Will you know how many items need to go into the array at runtime? If so, then you can declare the array at a fixed size based on that. If not, then you will need to ReDim it for each thing you have to add to it. When you redim, you need to preserve the contents. Usually you do something like this:

Dim aryMyArray()

For Each Thing
    ReDim Preserve aryMyArray(UBound(aryMyArray)+1)
    aryMyArray(UBound(aryMyArray)) = Thing
Next Thing

The array datatype doesn't have a "search" function, so you'll have to write your own lookup loop.

For i = 0 To UBound(aryMyArray)
    If aryMyArray(i) = LookupThing Then...
Next i

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 21st, 2003, 11:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Peter, I have to disagree with you there. A dictionary object is much more efficient than an array at being re-sized, plus it has the Exists method to easily locate any item already in the dictionary. For these reasons its much better suited to the OP's requirements.

rgds
Phil
 
Old November 21st, 2003, 12:14 PM
Authorized User
 
Join Date: Nov 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to both of you!

I really needed that expertise about arrays anyhow ;) and surely there will be a great use for Dictionary as well!

tnx!
/Paw






Similar Threads
Thread Thread Starter Forum Replies Last Post
strings as array indexes cwalton Excel VBA 3 July 30th, 2007 02:50 AM
Array of Strings to dll jjd Excel VBA 2 February 26th, 2006 07:25 AM
Array of Strings jjd Visual C++ 1 June 23rd, 2005 02:56 PM
Storing and Displaying Formatted Strings anubhav.kumar Classic ASP Professional 17 October 26th, 2004 10:17 PM
Autofill in unknown number of rows ashu_gupta75 Excel VBA 2 August 9th, 2004 06:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.