「VBScript入門」SortedListクラスのサンプル
書式
GetKey(Int32)
SortedList オブジェクトの指定したインデックスにあるキーを取得します。
使用例
Dim cftSortLst
Set cftSortLst = CreateObject("System.Collections.SortedList")
' 要素を追加
cftSortLst.Add "city01", "testvalue:001"
cftSortLst.Add "city03", "testvlaue:003"
cftSortLst.Add "city04", "testvlaue:004"
cftSortLst.Add "city02", "testvalue:002"
' ソート順
Dim n
For n =0 to cftSortLst.Count -1
Wscript.echo "element:" & cftSortLst.GetKey(n) & ", " & cftSortLst.GetByIndex(n)
Next
' 要素を削除
cftSortLst.Clear
Dim cftSortLst
Set cftSortLst = CreateObject("System.Collections.SortedList")
' 要素を追加
cftSortLst.Add "city01", "testvalue:001"
cftSortLst.Add "city03", "testvlaue:003"
cftSortLst.Add "city04", "testvlaue:004"
cftSortLst.Add "city02", "testvalue:002"
' ソート順
Dim n
For n =0 to cftSortLst.Count -1
Wscript.echo "element:" & cftSortLst.GetKey(n) & ", " & cftSortLst.GetByIndex(n)
Next
' 要素を削除
cftSortLst.Clear
Dim cftSortLst Set cftSortLst = CreateObject("System.Collections.SortedList") ' 要素を追加 cftSortLst.Add "city01", "testvalue:001" cftSortLst.Add "city03", "testvlaue:003" cftSortLst.Add "city04", "testvlaue:004" cftSortLst.Add "city02", "testvalue:002" ' ソート順 Dim n For n =0 to cftSortLst.Count -1 Wscript.echo "element:" & cftSortLst.GetKey(n) & ", " & cftSortLst.GetByIndex(n) Next ' 要素を削除 cftSortLst.Clear
実行結果
element:city01,testvalue:001
element:city02,testvalue:002
element:city03,testvalue:003
element:city04,testvalue:004