Array issue

1. Senior Member
Join Date
Dec 1969
Posts
604

## Array issue

I have a value that is a numerical array, say<BR><BR>1,505,7676,190<BR><BR>I want to show a set of 10 checkboxes which are checked if their value is in the array.<BR><BR>I guess I could use the Instr function but, in the example above, &#060;%If Instr(aArray, "1")%&#062; would return True TWICE although 1 is only present ONCE.<BR><BR>Any solution?

2. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## What?

first of all i dont think you are telling us the entire story<BR><BR><BR>secondly if you did an Instr to check for 1 it would return true EVERY time cause the STRING would always have 1...unless you change it<BR><BR>having said that if you are checking the array elements for a value and then looking for 1<BR><BR>you will have to make a small change....somthing like this<BR><BR>instr("," & aArray(i) & ",", ",1,")<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
109

## Programming as a Science...

Seems like we are becoming more and more dependent on built-in functions/methods/classes/objects, etc.<BR><BR>Look into Filter() &#060;--- hasn&#039;t helped me much, though. :-)<BR><BR>If you have an integer array, why not use some of the<BR>fundamental algorithms? Especially if the array is static!<BR><BR>You could use Radix-Sort, which runs in O(n) to sort the<BR>array. Then you could use a binary search method O(log-2 n)<BR><BR>I really like Radix-Sort, it&#039;s a really neat concept!<BR>May I suggest looking at NIST:<BR>http://www.nist.gov/dads/<BR><BR>Of course any sorting algorithm would be just fine.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## I give up...

...what&#039;s the point of sorting that array???<BR><BR>So that then you can do a binary search to see if a given value is contained within it?<BR><BR>Yeah, might be worthwhile if the array has hundreds of elements or more.<BR><BR>But the INSTR solution given by Akhilesh will be *much* faster for the small pseudo-array he has ("pseudo" because it&#039;s not an array, of course...it&#039;s just a delimited string). Among other things, the INSTR code will function at machine speed (since it&#039;s compiled C++ code) whereas any solution such as sort-and-binary-search will have to run in VBScript code which is orders of magnitude slower.<BR><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
•