0

This code causes an error for me:

i = 0
Set colors = CreateObject("Scripting.Dictionary")
Do While i < 7
    If True Then
        Dim a(1)
        a(0) = "go"
        a(1)  = "tRY"
        colors.Add "space", a
    End If
    i = i + 2
Loop

I'm not too sure why. I need to do something similar, where I initialize a dictionary with one array for each key, but the while loop seems to be messing it up. Any suggestions? Thanks!

2
  • 2
    For future reference: When you write "causes an error", it's very helpful to us if you include the information about what "an error" is, so we don't have to try to guess. You already have that information right in front of you, so there's absolutely no reason to fail to include it in your question. It's to your benefit to give us the relevant information; it helps you get answers more quickly. When posting, please remember that we can't see your screen or read your mind from where we sit. Commented Jun 18, 2014 at 22:01
  • Sorry about that, I'll make sure to do that in the future. Commented Jun 19, 2014 at 21:28

1 Answer 1

2

Once you've dimmed an array, it cannot be dimmed again. It can, however, be ReDimed. Dim it outside the loop. If you want to clear the array during each loop, you can do one of the following:

ReDim a(1)    ' ReDim without 'Preserve' will clear the array
' or
Erase a
Sign up to request clarification or add additional context in comments.

Comments

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.