create and search array

how to search an array for the position of first occurence

Page 1 of 1

1 Replies - 4213 Views - Last Post: 30 March 2009 - 05:23 AM Rate Topic: -----

#1 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 195
  • Joined: 03-December 08

create and search array

Post icon  Posted 25 March 2009 - 08:22 AM

Hello and thanks for your time.

I am hoping to learn how to create an array from a database query, and then search the array for the position of the first occurence of a specific integer. I have done this successfully using InStr but I was wondering if it is possible in this manner...

<%

Dim strValue

strValue = rs2("COC")

Dim myArray

myArray = split(strValue,";")

Dim returnValue

returnValue = Array.Find(myArray, 17)
Response.Write(returnValue)

%>



First I dimension strValue and set it to a database queried value of rs("COC") which is the following string...
15;223;17;890;314

Then I split the string using ; as my separator, and I get this...

15
223
17
890
314

the next bit of code is where I am sure I trip up; the Array.find(myArray, 17)

Does this search myArray for the position of the first occurence of 17? Or am I understanding this wrong?

Also, is there a way to replace the semicolons with commas before I perform the split?

Thanks for any help!

This post has been edited by midasxl: 25 March 2009 - 09:05 AM


Is This A Good Question/Topic? 0
  • +

Replies To: create and search array

#2 midasxl  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 195
  • Joined: 03-December 08

Re: create and search array

Posted 30 March 2009 - 05:23 AM

OK, I figured this out BY MYSELF, thank you!

Dim strValue, myArray, position1, position2, counter

	strValue = rs1("COC")'record set return from database query
		
		myArray = split(strValue,";")
'this split my string using; as the separator
		For counter = LBound(myArray) to UBound(myArray) 
'i use cint to convert the strings (which are an array of numbers")to integers
		If cint(myArray(counter)) = rs("ID") Then	
		position1 = counter
		Exit For
		else
		position1 = 0


		End If
		Next



Rock and Roll!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1