2012-07-13 2 views
9

VBAを使用していますので、データをkey =>valueに保存する必要があります。このデータ型は、HTTP要求から応答テキストをキャッシュして、クエリ速度を向上させます。しかし、私はそれを行う最良の方法は何か分かりません。私はkey=>valueとPHP配列と同じデータ型が必要です!助けてくれてありがとう!PHPの配列と同じようにデータを保存するための最良のVBAデータ型 `key` =>` value`はどれですか?

+2

の可能重複[?んVBA辞書構造を持っている](http://stackoverflow.com/questions/915317/does-vba-have-dictionary-structure) –

答えて

14

辞書オブジェクトを見ましたか?

Sub DictExample1() 

Dim dict As Dictionary 
Dim v As Variant 

    'Create the dictionary   
    Set dict = New Dictionary 

    'Add some (key, value) pairs 
    dict.Add "John", 34 
    dict.Add "Jane", 42 
    dict.Add "Ted", 402 

    'How many items do we have? 
    Debug.Print "Number of items stored: " & dict.Count 

    'We can retrieve an item based on the key 
    Debug.Print "Ted is " & dict.Item("Ted") & " years old" 


    'We can test whether an item exists 
    Debug.Print "We have Jane's age: " & dict.Exists("Jane") 
    Debug.Print "We have Zak's age " & dict.Exists("Zak") 

    'We can update a value by replacing it 
    dict.Item("Ted") = dict.Item("Ted")/10 

    Debug.Print "Ted's real age is: " & dict.Item("Ted") 

    'We can add more items 
    dict.Add "Carla", 23 

    'And we can iterate through the complete dictionary 
    For Each v In dict.Keys 
     Debug.Print "Name: " & v & "Age: "; dict.Item(v) 
    Next 

End Sub 

(出典:http://www.techbookreport.com/tutorials/vba_dictionary.html

+0

ありがとうございました!わかった! – Davuz

+2

他のサイトへの参照はしないでください。これは、あなたが解決策を書くことができる場所です。 –

+3

@PawelMiechowiecki:URLに余分な情報を提供すると何が問題になりますか?特に、このコードを動作させるためには、「Microsoft Scripting Runtime」への参照を有効にする必要があります... –

関連する問題