WSH/配列の要素数を取得する方法
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* VBScriptで配列の要素数を取得する方法 [#sfa7f59b]
UBound関数を使用することにより配列の要素数を取得すること...
以下に配列要素数を取得するサンプルコードを以下に記します。
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* UBound関数 [#hb2205c0]
一次元配列であれば以下のように配列変数を指定すれば最大イ...
配列は0から始まるので要素数を求めるには最大インデックス値...
UBound(配列変数)
多次元配列の場合は、配列変数名と次元を指定する必要があり...
以下のような3次元配列があり
Dim a(1, 2, 3)
3番目の最大インデックス値を求めたい場合は以下のようになり...
UBound(a, 3)
* Arrayで取得した場合のサンプル [#b17d9b98]
以下のようなサンプルコードにて要素数を取得
-サンプルコード &ref(ubound01.vbs);
a = Array(1, 2, 3, 4, 5)
WScript.Echo "UBound(a) = " & UBound(a)
WScript.Echo "UBound(a)+1 = " & UBound(a)+1
- 実行結果
C:\wsh>cscript /nologo ubound01.vbs
UBound(a) = 4
UBound(a)+1 = 5
* Dimで取得した場合のサンプル [#mf57661e]
以下では一次元、二次元、三次元配列の場合の要素数を取得す...
- サンプルコード &ref(ubound02.vbs);
Dim x(10)
Dim xy(10,20)
Dim xyz(10,20,30)
WScript.Echo "UBound(x)+1 = " & UBound(x)+1
WScript.Echo "UBound(xy, 1)+1 = " & UBound(xy, 1)+1
WScript.Echo "Ubound(xy, 2)+1 = " & Ubound(xy, 2)+1
WScript.Echo "UBound(xyz, 1)+1 = " & UBound(xyz, 1)+1
WScript.Echo "Ubound(xyz, 2)+1 = " & Ubound(xyz, 2)+1
WScript.Echo "UBound(xyz, 3)+1 = " & UBound(xyz, 3)+1
- 実行結果
C:\wsh>cscript /nologo ubound02.vbs
UBound(x)+1 = 11
UBound(xy, 1)+1 = 11
Ubound(xy, 2)+1 = 21
UBound(xyz, 1)+1 = 11
Ubound(xyz, 2)+1 = 21
UBound(xyz, 3)+1 = 31
上記のように、UBound関数により配列の次元の最大インデック...
配列は0からはじまるので、UBound関数の戻り値に+1することに...
#htmlinsertpcsp(win-btm.html,win-sp.html)
終了行:
#navi(../)
* VBScriptで配列の要素数を取得する方法 [#sfa7f59b]
UBound関数を使用することにより配列の要素数を取得すること...
以下に配列要素数を取得するサンプルコードを以下に記します。
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* UBound関数 [#hb2205c0]
一次元配列であれば以下のように配列変数を指定すれば最大イ...
配列は0から始まるので要素数を求めるには最大インデックス値...
UBound(配列変数)
多次元配列の場合は、配列変数名と次元を指定する必要があり...
以下のような3次元配列があり
Dim a(1, 2, 3)
3番目の最大インデックス値を求めたい場合は以下のようになり...
UBound(a, 3)
* Arrayで取得した場合のサンプル [#b17d9b98]
以下のようなサンプルコードにて要素数を取得
-サンプルコード &ref(ubound01.vbs);
a = Array(1, 2, 3, 4, 5)
WScript.Echo "UBound(a) = " & UBound(a)
WScript.Echo "UBound(a)+1 = " & UBound(a)+1
- 実行結果
C:\wsh>cscript /nologo ubound01.vbs
UBound(a) = 4
UBound(a)+1 = 5
* Dimで取得した場合のサンプル [#mf57661e]
以下では一次元、二次元、三次元配列の場合の要素数を取得す...
- サンプルコード &ref(ubound02.vbs);
Dim x(10)
Dim xy(10,20)
Dim xyz(10,20,30)
WScript.Echo "UBound(x)+1 = " & UBound(x)+1
WScript.Echo "UBound(xy, 1)+1 = " & UBound(xy, 1)+1
WScript.Echo "Ubound(xy, 2)+1 = " & Ubound(xy, 2)+1
WScript.Echo "UBound(xyz, 1)+1 = " & UBound(xyz, 1)+1
WScript.Echo "Ubound(xyz, 2)+1 = " & Ubound(xyz, 2)+1
WScript.Echo "UBound(xyz, 3)+1 = " & UBound(xyz, 3)+1
- 実行結果
C:\wsh>cscript /nologo ubound02.vbs
UBound(x)+1 = 11
UBound(xy, 1)+1 = 11
Ubound(xy, 2)+1 = 21
UBound(xyz, 1)+1 = 11
Ubound(xyz, 2)+1 = 21
UBound(xyz, 3)+1 = 31
上記のように、UBound関数により配列の次元の最大インデック...
配列は0からはじまるので、UBound関数の戻り値に+1することに...
#htmlinsertpcsp(win-btm.html,win-sp.html)
ページ名: