arrays...finding stuff inside!

Results 1 to 2 of 2

Thread: arrays...finding stuff inside!

  1. #1
    Join Date
    Dec 1969

    Default arrays...finding stuff inside!

    I have an array<BR>Dim itemslist<BR>itemslist = Array (" & itemnums & ")<BR><BR>result...........itesmlist contains 1,2,4,8 for example.<BR><BR>When i get a rs from a database and loop through it, I wnat to check to see if the itemid of the current record is in the array and if so do something! <BR><BR>NAy ideas??

  2. #2
    Join Date
    Dec 1969

    Default RE: arrays...finding stuff inside!

    Ugh. Let me suggest you don&#039t use this approach for a number of reasons. First, finding an element in an array, is, at best, LOG N, where N is the number of elements in the array (this is only when the array is sorted, if it is unsorted, you&#039re time is N). If you have M elements in your recordset, then the best you can do is M LOG N. This isn&#039t good, especially if M or N are large.<BR><BR>What I recommend you do is use SQL&#039s set notation to grab just those recordsets that have their ID equal to the values you are interested in. For example:<BR><BR>SELECT * FROM Table1<BR>WHERE ID IN (1, 2, 4, 8)<BR><BR>or, in a more dynamic sense:<BR><BR>strSQL = "SELECT * FROM Table1 WHERE ID IN (" & itemnums & ")"<BR><BR>This article should get you started on your way (although it shows how to delete records, you can use a similar approach to select records)<BR><BR><BR>Happy Programming!<BR>

Posting Permissions

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