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!

Looping logic???? 1

Status
Not open for further replies.

Cheech

Technical User
Nov 6, 2000
2,933
EU
Hi,
I am trying to assign a recordset into an array and keep getting a type mismatch error, iCount is a number as is cat_id.

anyone see where I am going wrong?


iCount = 0
Do Until rsCatid.EOF
arrCatid(iCount) = (rsCatid.Fields.Item("cat_id").value)
arrCatname(iCount) = rsCatid.Fields.Item("cat_name").value
iCount = iCount + 1
rsCatid.Movenext
Loop The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Cheech,

I don't know if this will help but we don't use .fields.item. We just say something like:


arrCatid(iCount) = (rsCatid.Fields("cat_id"))
arrCatname(iCount) = rsCatid.Fields("cat_name")

Hope this helps,

Tom

 
Cheers Tom,

but unfortunately that didn't work.

I think my proble lies with declaring the arrays with the dim statement.

If I use
dim arrCatid()
I get a subscript out of range error
dim arrCatid(some_intger_value)
gives an "expected integer" error
dim arrCatid(500)
works fine but as I dont know how many records will be added to the array I guess what I am really asking is how to "dim" an array without knowing a value to give it The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
sounds like you need a dynamic array:

Code:
iCount = 0
Dim arrCatid()
Dim arrCatname()

Do Until rsCatid.EOF
Redim Preserve arrCatid(iCount)
Redim Preserve arrCatname(iCount)
arrCatid(iCount) = (rsCatid.Fields.Item("cat_id").value)
arrCatname(iCount) = rsCatid.Fields.Item("cat_name").value
iCount = iCount + 1
rsCatid.Movenext
Loop


Redim will resize the array but will also clear its contents. Using Redim Preserve will resize the array but preserve the contents.

Hope this helps

Tony
 
Your a star. FesterSXS, I kinda knew what it was I needed to do but you made me realise it The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Worked like a dream, only to glad to award a star.

As someone who advises in the Dreamweaver Ultradev forum I know that a star is often the best thanks you can get. The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top