Results 1 to 21 of 21

Thread: Timer1 control array to Redim preserve

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    VB Code:
    1. Private Function FindFree_Timer As Integer
    2. Dim intIterate As Integer
    3.  
    4.    FindFree_Timer = 0
    5. On Error Goto ErrorHandler
    6.    For intIterate = 1 To Timer1.Ubound
    7.       Timer1(intIterate).Tag = Timer1(intIterate).Tag  
    8.    Next
    9. On Error Goto 0
    10.  
    11.    'FindFree_Timer = 0  since all are loaded
    12.    Exit Function
    13.  
    14. ErrorHandler:
    15. 'Goes here if instance does not exist
    16.    FindFree_Timer = intIterate
    17.    Err.Clear
    18. End Sub
    19.  
    20.  
    21. Public Function Assigned_TimerIndex As Integer
    22. Dim intRetIndex As Integer
    23.  
    24.    intRetIndex = FindFree_Timer
    25.    If intRetIndex = 0 Then
    26.       Load Timer1(Timer1.Ubound + 1)
    27.       Timer1(Timer1.Ubound).Interval = 5000   'Ubound updates
    28.       Assigned_TierIndex = Timer1.Ubound
    29.    Else
    30.       Load Timer1(intRetIndex)
    31.       Timer1(intRetIndex).Interval = 5000
    32.       Assigned_TierIndex = intRetIndex
    33.    End if
    34. End Sub

    That should fill up your holes. Admittedly, they won't be in order of creation.... but do you really want to bother with that? In the end, you wont have miore than 32K students being assigned timers anyway.

    You can modify the concept to skip over the holes if your iterating through the control array. Either create a list of loaded indices or use On Error Resume Next to ignore the error with unloaded indices.
    Last edited by leinad31; Jan 15th, 2004 at 02:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width