1

以下のコードには、テスト配列があります。400 から 500 の範囲内にあるが、Test 配列 ( Ex: 410 - Although this value is in the range of 400 to 500, it is not found in the array) に見つからない値を検索したい 見つかったら、それを新しいコレクションに追加し、新しいアクション ( などset the value of it to 410|New-value) を実行して表示する必要がありますウェブページ。

コードは次のとおりです。

Test= Array("1|Name", "2|Place", "400|Animal", "420|Thing")

For Each x in Test
    xSplit=Split(x,"|")
    'Do Something'          
Next    
    'Do Something'

誰でもこれについて私を助けることができますか?

4

1 に答える 1

1

どうやらそこにはキーと値のペアがあるため、適切なデータ構造はおそらくディクショナリです。

Set dict = CreateObject("Scripting.Dictionary")
For Each x in Test
  xSplit = Split(x, "|")
  dict.Add xSplit(0), xSplit(1)
Next

そうすれば、キー値が存在するかどうかを簡単に確認できます。

If dict.Exists(42) Then
  WScript.Echo dict(42)
Else
  WScript.Echo "Index 42 does not exist."
End If
于 2012-09-12T10:04:57.807 に答える