Problem: Late binding error with arraylist

V

VB Programmer

I have an arraylist which holds a custom structure I made. (The structure
contains FirstName, LastName, Address and EmpId.)

I am trying to loop through the arraylist to write out each item. Here's
the code:
Dim i As Integer
For i = 0 To alRecentActivity.Count - 1
Debug.Write(alRecentActivity.Item(i).FirstName)
Next

Problem. It puts a blue squiggly under alRecentActivity.Item(i).FirstName
that says "Option Strict On disallows late binding". I want to keep Option
Strict On. Any ideas how I can loop through the arraylist and retrieve
particular values of each item?

Thanks.
 
V

VB Programmer

NM. I just converted the arraylist item to the structure type then accessed
the variables that way.

Ex:
Dim x as MyStructure
For i = 0 to alRecentActivity.Count - 1
x = CType(alRecentActivity.Item(i), MyStructure)
Debug.Write(x.FirstName)
Next

Any alternatives would be appreciated as well.

Thanks.
 
J

John Saunders

VB Programmer said:
NM. I just converted the arraylist item to the structure type then accessed
the variables that way.

Ex:
Dim x as MyStructure
For i = 0 to alRecentActivity.Count - 1
x = CType(alRecentActivity.Item(i), MyStructure)
Debug.Write(x.FirstName)
Next

If you know that each entry is of the MyStructure type, then use
DirectCast(alRecentActivity(i), MyStructure) instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top