VBScriptの配列は貧弱で、要素の追加や並び替え(ソート)、重複の排除など、配列操作のための関数がそろっていない。特に厄介だと思うのは、簡単に要素の追加ができないというところ。JavaScriptでいうarray.push()みたいなことが標準ではできないから、ある場面においては非常に扱いにくい。
なので、配列操作の比較表:VBScript, VimScript - メモ帳を参考に、拡張した配列クラスを作ってみた。(ソート関数は時間のあるときに実装する。)
<% Option Explicit Class ArrayManager Private name ' コンストラクタ Private Sub Class_Initialize name = "ArrayManager" End Sub ' デストラクタ Private Sub Class_Terminate End Sub Public Function GetName() GetName = name End Function ' 要素の追加 Public Sub Push(x, y) ReDim Preserve x(UBound(x) + 1) x(UBound(x)) = y End Sub ' 要素数の取得 Public Function Length(x) Length = UBound(x) - LBound(x) + 1 End Function ' 配列のクリア Public Sub Clear(Byref x) x = Array() End Sub ' 最初の要素を取得 Public Function First(x) First = x(0) End Function ' 最後の要素を取得 Public Function Last(x) Last = x(UBound(x)) End Function ' 重複を排除した配列を返す Public Function UniqueArray(x) Dim l_intI Dim l_intMax Dim l_dicTmp l_intMax = UBound(x) If l_intMax <= 0 Then UniqueArray = x Exit Function End If Set l_dicTmp = CreateObject("Scripting.Dictionary") For l_intI = 0 To l_intMax If Not l_dicTmp.Exists(x(l_intI)) Then l_dicTmp.Item(x(l_intI)) = "" End If Next UniqueArray = l_dicTmp.keys Set l_dicTmp = Nothing End Function End Class %>