Timer and ArrayList
Hi,
I have an array list which I would like an event to be triggered for each item in the list at a timed interval.
eg;
item(a)
item(b)
item(c)
after 5 seconds a message box with item(a) will appear
after 5 seconds a message box with item(b) will appear
after 5 seconds a message box with item(c) will appear
Is there a simple way of doing this with VB .Net?
[413 byte] By [
LungBeat] at [2007-12-24]
well you would have to know the last position that was used to get the item from the array, so perhaps make this a global scoped variable, something like "lastPosition" and declare it as an integer. Then on the timer interval tick event simply get that last position, + 1 and show it. Example:
Drag and drop the timer control on your form in designer view
Set the interval you want (in milliseconds). Start the timer whenever you want in the application.
Go into code view then:
'Declare globally:
Dim theLastPosition as Integer = 0 'default value of 0
'where is that arraylist stored? make it global so you can access it from any where in the class
Dim theArrayList as new ArrayList()
back in designer view, double click the timer to create a timer tick event. Then do this in the timer tick event:
if Me.theArrayList.Count > 0 And Me.theArrayList.Count < theLastPosition then
MessageBox.Show(Me.theArrayList(Me.theLastPosition).ToString())
theLastPosition = theLastPosition + 1
end if
then start the timer wherever in your application. Of course make sure you populate the items in the arraylist!
does this help? Does this work for you?