LoginSignup
8
7

More than 5 years have passed since last update.

【VBS】ArrayList

Last updated at Posted at 2016-01-31

前述

VBScript(WSH)で動的配列のArrayListを使いたい。
配列を使って要素が増える度にReDimするのは面倒くさいので、.NetのArrayListオブジェクトを作成して使う。
言語仕様的に使えないメソッドもあるようだが、SortやClearも使うことができる。

ソース

ArrayList
Option Explicit

' ArrayList作成
Dim ary
Set ary = CreateObject("System.Collections.ArrayList")

' 要素追加
ary.add "AK-47"
ary.add "M4"
ary.add "G3"

' 要素数取得
Dim num
num = ary.Count

WScript.Echo "要素数: " & num

' For Each文によるループ処理
Dim item
For Each item In ary
    WScript.Echo item
Next

' 要素ソート
ary.Sort

For Each item In ary
    WScript.Echo item
Next

' 要素クリア
ary.Clear


' 破棄
Set ary = Nothing
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7