2012-07-13 13 views
9

Sto lavorando con VBA e ho bisogno di salvare i dati nel tipo key =>value per ottenere il più veloce; Questo tipo di dati mi aiuta a memorizzare il testo in risposta alla richiesta http, aumentare la velocità della query. Ma non so qual è il modo migliore per farlo? Ho bisogno di un tipo di dati come php array con key=>value! Grazie per l'aiuto!Qual è il migliore tipo di dati VBA `key` => `valore` per salvare i dati come array PHP

+2

possibile duplicato del [fa VBA hanno una struttura Dictionary?] (Http://stackoverflow.com/questions/915317/does-vba-have-dictionary-structure) –

risposta

14

Hai guardato l'oggetto dizionario?

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 

(Fonte: http://www.techbookreport.com/tutorials/vba_dictionary.html)

+0

Grazie! Ho capito! – Davuz

+2

Per favore, non fare riferimenti ad altri siti. Questo è il posto dove puoi scrivere la soluzione. –

+3

@PawelMiechowiecki: Cosa c'è che non va fornendo URL con informazioni extra? Specialmente perché per far funzionare questo codice devi abilitare il riferimento a "Microsoft Scripting Runtime" quale passo è descritto nell'URL specificato ... –

Problemi correlati