2

I Declare an 2D Unlimited array. My code:

Dim array As String(,) = New String(,) {}
        array(0, 0) = "top left"
        MsgBox(array(0, 0))

The problem is the msgbox shows nothing.

6
  • There is no such thing as an “unlimited array” in VB. Commented Apr 30, 2012 at 15:49
  • only please tell me how i can do this code works without an specific range? Commented Apr 30, 2012 at 15:54
  • What are you trying to do with your 2D array? Commented Apr 30, 2012 at 15:55
  • 1
    @Jonathan You can’t with the built-in array, you have to create your own class which uses e.g. a Dictionary internally. Commented Apr 30, 2012 at 16:04
  • @JonathanEdgardo, check out stackoverflow.com/questions/4255308/… (idea Konrad brings out) Commented Apr 30, 2012 at 16:06

1 Answer 1

0

You can change the array bounds when needed with ReDim Preserve, which copies the existing array into an array with new dimensions.

But it might be simpler to use a List instead, which is "unlimited" (no need to specify range, or resize manually). But a list only has one dimension. To mimick a 2D array, you could have a List of Lists (each List item is a List itself).

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.