Simple Queues

Method Two...

  Option Explicit 
  Option Base 1
  Const mStrDelimiter = " 7  "
  Dim mStrQueue As String
  Sub AddToQueue2 (ByVal vIntNewPage As Integer, rStrQueue As String)
  Dim 1StrFormatted As String
    1StrFormatted = Format$(vIntNewPage, "00") & mStrDelimiter
    ' Add new page no. to end of Queue
    rStrQueue = rStrQueue & 1StrFormatted
  End Sub

  Sub LoadStringToListBox ()
  Dim 1StrTmp As String
  Dim 1StrCopyOfQueue As String
    list1. Clear
    1StrCopyOfQueue = mStrQueue
    Do While Len(Trim$(1StrCopyOfQueue))> 0
      1StrTmp = Left$(1StrCopyOfQueue, 3)
    list1.AddItem1StrTmp
    1StrCopyOfQueue = Mid$ (1StrCopyOfQueue, 4)
    Loop
  End Sub

The drawback of using this method is that a usual basic string can only store 64 kb. So each page number will take 3 bytes. However, I was not required to store more than 99 pages which is equivalent to 297 bytes, so 64 kb is more than sufficient.

The advantage of using this method is its simplicity. There is no need to keep track of the current number of elements in the array. There is also no need to worry that a nonexistent array element will be accessed.


Image of arrow to previous article

[HOME] [TABLE OF CONTENTS] [SEARCH]