Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

homepyrof53

XLDnaute Occasionnel
Bonjour,
J'utilise souvent :
Code:
Dim tab1
Set tab1 = CreateObject("scripting.dictionary")

Dans la la fenêtre afficher les variables locales on a:
tab1
Item 1
Item 2
......

Je souhaiterai récuper les valeurs en utilisant ces Item :
x=tab1.item(2) mais ça ne fonctionne pas
Quelqu'un connait-il la syntaxe
Merci
 
Re : Item et dictionnary

Bonjour homepyrof53,
Regarde de code si il peut t'aider.

Code:
[COLOR=blue]Sub[/COLOR] dico()
[COLOR=blue]Dim[/COLOR] tab1
[COLOR=blue]Set[/COLOR] tab1 = CreateObject("scripting.dictionary")
[COLOR=blue]For[/COLOR] i = 1 [COLOR=blue]To[/COLOR] 11
    tab1.Item(i) = Cells(i, 1)
[COLOR=blue]Next[/COLOR] i
Var = tab1.Item(3)
MsgBox Var
[COLOR=blue]End Sub[/COLOR]

Cordialement
 
Re : Item et dictionnary

Ta solution fonctionne car tu utilise Item pour alimenter ton tableau

Voila le code je j'utilise :

Code:
Sub toto()
Dim tab1
Set tab1 = CreateObject("scripting.dictionary")

tab1("B") = "B"
tab1("C") = "C"
tab1("E") = "E"
tab1("D") = "D"
tab1("A") = "A"
nb_item=tab1.count
x = tab1.Item(3)
End Sub

x retourne vide !!!!!!!!!!!!!!!!!
 
Re : Item et dictionnary

Bonjour le fil 🙂,
Au choix :
Code:
Sub toto()
Dim tab1
Set tab1 = CreateObject("scripting.dictionary")
tab1("B") = "B"
tab1("C") = "C"
tab1("E") = "E"
tab1("D") = "D"
tab1("A") = "A"
nb_item = tab1.Count
x = tab1.Item("C")
MsgBox x
End Sub
Code:
Sub toto()
Dim tab1
Set tab1 = CreateObject("scripting.dictionary")
tab1(2) = "B"
tab1(3) = "C"
tab1(5) = "E"
tab1(4) = "D"
tab1(1) = "A"
nb_item = tab1.Count
x = tab1.Item(3)
MsgBox x
End Sub
Bonne journée 😎
 
Re : Item et dictionnary

Bonsoir,

L'item(3) n'existe pas, 3 désignant une clé....
Or tu ne rentres que des clés alphabétiques...

Tu peux essayer ainsi :

Code:
Sub toto()
Dim tab1 As Object
Set tab1 = CreateObject("scripting.dictionary")

tab1("B") = "B"
tab1("C") = "C"
tab1("E") = "E"
tab1("D") = "D"
tab1("A") = "A"
nb_item = tab1.Count
tmp1 = Application.Transpose(tab1.items)
tmp2 = Application.Transpose(tab1.keys)
x = tmp1(3, 1)
y = tmp2(3, 1)
End Sub

Bonne soirée
 
Re : Item et dictionnary

Re 🙂,
Bonjour Efgé, Bh² 😉
Ou encore
Code:
Sub toto()
Dim tab1
Set tab1 = CreateObject("scripting.dictionary")
tab1("B") = "B"
tab1("C") = "C"
tab1("E") = "E"
tab1("D") = "D"
tab1("A") = "A"
nb_item = tab1.Count
x = tab1.items
For i = LBound(x) To UBound(x)
MsgBox x(i)
Next i
End Sub
Bon courage 😎
 
Re : Item et dictionnary

salut

à voir
Code:
Sub toto()
  Dim tab1
  Set tab1 = CreateObject("scripting.dictionary")
  For n = 65 To 69 'de A à E
    tab1(Chr(n)) = [B]0[/B]        '= [B]n'importe quoi[/B]
  Next
  a = tab1.keys
  MsgBox a(4) 'attention, l'index du 1er item est 0
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Réponses
1
Affichages
669
Retour