VBAで .NET Framework の Queue Stack SortedListを使ってみた。
で、どうした。って感じだけど。
Option Compare Database
Option Explicit
'Queue FIFO
'http://msdn.microsoft.com/ja-jp/library/system.collections.queue.aspx
Sub queueDNF()
Dim q As Object, q2 As Object, l As Object
Set q = CreateObject("System.Collections.Queue")
q.Enqueue "Hello"
q.Enqueue "World"
q.Enqueue "!!"
Set q2 = q.Clone
Debug.Print q.Peek, q.Count
Debug.Print q.Dequeue, q.Count
Debug.Print q.Dequeue, q.Count
Debug.Print q.Dequeue, q.Count
q2.Enqueue "ハロー"
Do Until q2.Count = 0
Debug.Print q2.Dequeue
Loop
End Sub
' Stack LIFO
'http://msdn.microsoft.com/ja-jp/library/system.collections.stack.aspx
Sub stackDNF()
Dim s As Object, s2 As Object
Set s = CreateObject("System.Collections.Stack")
s.Push "Hello"
s.Push "World"
s.Push "!!"
Set s2 = s.Clone
Debug.Print s.Peek, s.Count
Debug.Print s.Pop, s.Count
Debug.Print s.Pop, s.Count
Debug.Print s.Pop, s.Count
s2.Push "ハロー"
Do Until s.Count = 0
Debug.Print s.Pop
Loop
End Sub
'SortedList
'http://msdn.microsoft.com/ja-jp/library/system.collections.sortedlist.aspx
Sub sortedlistDNF()
Dim sl As Object
Set sl = CreateObject("System.Collections.SortedList")
Debug.Print sl.Capacity
sl.Capacity = 3
sl.Add 2, "World"
sl.Add 1, "Hello"
sl.Add 3, "!!"
Debug.Print sl.Count, sl.Item(1)
Debug.Print sl.ContainsKey(2)
Debug.Print sl.ContainsValue("!!!")
Dim kl As Object
Set kl = sl.GetKeyList
Debug.Print kl(0), kl(1), kl(2)
Debug.Print sl.GetByIndex(0)
sl.SetByIndex 0, "ハロー"
sl.SetByIndex 2, "??"
Debug.Print sl.IndexOfValue("World")
Debug.Print sl.IndexOfKey(3)
Dim vl As Object
Set vl = sl.GetValueList
Debug.Print vl(0), vl(1), vl(2)
Do Until sl.Count = 0
Debug.Print sl.GetByIndex(0)
sl.RemoveAt 0
Loop
End Sub
0 件のコメント:
コメントを投稿