Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing first element of a collection

Status
Not open for further replies.

WorkerBeeJ

Programmer
Aug 6, 2002
34
US
I'm having trouble accessing the first element of a collection created with a regular expression. I know that the regular expression execute is working correctly because I can iterate through the entire collection with a for each statement. But I only need the first element. Can anyone tell me what I'm doing wrong here?

'''''Begin partial code

DO WHILE NOT rs.EOF
add1 = rs.Fields("Address1")
if not isNull(add1) then
set words = wholeWordRegExp.Execute(add1)
set word = words(0)
'do other stuff
end if
rs.MoveNext
LOOP

'''''End partial code

Thanks!
 
If I understand what you are after you can do this in the sql statement..

strSQL = "SELECT id,Address1 from table_name WHERE id=1 ORDER BY id ASC LIMIT 1"

ASC = accending (1,2,3 / a,b,c)
DESC = decending (3,2,1 / c,b,a)

Yes, I think thats correct. www.vzio.com
ASP WEB DEVELOPMENT



 
Thanks, but this isn't quite what I need. I need to access the first item in a collection not a database. This would be similar to accessing the first element in an array.
 
Oh okay, the "rs" through me off a bit.


For an array you can use:
Code:
strFirstItemInArray = strArray(UBound(strArray))

or you can modify your code, this should work:

DO WHILE NOT rs.EOF

If strFirstLoop = "" then strFirstLoop = True

add1 = rs.Fields("Address1")
if not isNull(add1) then
set words = wholeWordRegExp.Execute(add1)
set word = words(0)
'do other stuff
If strFirstLoop = True then
strFirstLoopVal = add1
strFirstLoop = False
End If

end if



rs.MoveNext
LOOP www.vzio.com
ASP WEB DEVELOPMENT



 
This isn't quite what I need.
But thanks for your input. :)

Does anyone else have any suggestions for how to access the first element of a collection?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top