txtOut.Text = s
txtOut.Refresh
Dim beasts As IStack
Select Case GetOption(optStack)
Case 0
Set beasts = New CStackLst
Case 1
Set beasts = New CStackVec
Case 2
Set beasts = New CStackCol
End Select
s = s & Space$(4) & “Push Lion” & sCrLf
beasts.Push “Lion”
s = s & Space$(4) & “Push Tiger” & sCrLf
beasts.Push “Tiger”
s = s & Space$(4) & “Push Bear” & sCrLf
beasts.Push “Bear”
s = s & Space$(4) & “Push Shrew” & sCrLf
beasts.Push “Shrew”
s = s & Space$(4) & “Push Weasel” & sCrLf
beasts.Push “Weasel”
s = s & Space$(4) & “Push Yetti” & sCrLf
beasts.Push “Yetti”
s = s & “Pop animals off stack: “ & sCrLf
Do While beasts.Count
s = s & Space$(4) & “Pop “ & beasts.Pop & sCrLf
Loop
Push animals onto stack:
Push Lion
Push Tiger
Push Bear
Push Shrew
Push Weasel
Push Yetti
Pop animals off stack:
Pop Yetti
Pop Weasel
Pop Shrew
Pop Bear
Pop Tiger
Pop Lion
In addition, the sample starts timing, pushes the number of integers specified by the Count text box onto a stack, pops them off, and then stops the timing. You can check the source in TCOLLECT.FRM. I’ll tell you the timing results later.
A Control Array Is Not an Array
One of the least understood data structures in Visual Basic is the control array. You won’t find it in the object browser and the documentation on it is…well, it exists, but not necessarily where you expect to find it.
‘ Find the True option from a control array of OptionButtons
Function GetOption(opts As Object) As Integer
On Error GoTo GetOptionFail
Dim opt As OptionButton
For Each opt In opts
If opt.Value Then
GetOption = opt.Index
Exit Function
End If
Next
On Error GoTo 0
ErrRaise eeNoTrueOption
Exit Function
GetOptionFail:
ErrRaise eeNotOptionArray
End Function