0

I am trying to store a multi dimensional array in VBA. I added the array to a key but I am not sure how I access it. I need to save an array of three for each key. The main array is a list of 15, 3 dimensional arrays.

Function test22()
  'Instanciate variables
  Set dict = New Scripting.Dictionary
  Dim hello As String
  hello = "Hello world"

  Dim test(0 To 15, 0 To 2) As String
  test(0, 0) = hello
  dict.add "key1", test

  'This line should print Hello World
  Debug.Print dict("key1").Value(0, 0)
End Function
2
  • What is an array of three? Commented Jul 12, 2018 at 15:16
  • Try declaring a variant and assigning the item to it: myVariable = dict("key1"). You should then be able to use myvariable as an MD array Commented Jul 12, 2018 at 15:22

1 Answer 1

1

You want

Debug.Print dict("key1")(0, 0)

dict("key1") will return an array. You then specify the location in that array directly as you would normally.

Sign up to request clarification or add additional context in comments.

11 Comments

Thanks for your reply but one more question. Is it possible to store the test 2 dimensional array in a dictionary. But I only want to store the first list in the array. I am trying but I get a wrong dimension error.
Please explain a little more. What is the code line that is failing for you?
For I = 0 To 15 'Data which should be going in for that key If I < 8 Then keyArray(I, 0) = departmentalData(I) Else keyArray(I, 0) = TBSdata(I - 8) End If keyArray(I, 1) = keys(I, 0) keyArray(I, 2) = keys(I, 1) keyArray(I, 3) = keys(I, 2) dict.Add keys(I, 0) & " " & keys(I, 1) & " " & keys(I, 2), keyArray(I) Next I
Sorry the code is formatted really poorly. What I am trying to do is have three attributes combined to make the primary key which is what I use for searching and I want an array of that key broken down.
dict.Add keys(I, 0) & " " & keys(I, 1) & " " & keys(I, 2), keyArray(I)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.