Results 1 to 12 of 12

Thread: [Resolved - silly me]2D arrays - silly q

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    [Resolved - silly me]2D arrays - silly q

    I have a dynamic array
    Code:
    dim myarray() as string
    Now I want to redim this array so I use :

    Code:
    redim preserve myarray(intctr)

    Works fine.

    But for two dimensional arrays - its giving me an error - subscript out of range. what do I do?
    Last edited by veryjonny; Jan 9th, 2002 at 07:02 AM.

  2. #2
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    It'll need to dimmed to a value first (such as 0)

    The first dim statement cannot be a redim preserve, as it hasn't yet been dimmed.

    That help?
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    Unhappy

    Thanks Arbiter for replying but,

    Nope didnt work.


  4. #4
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    Post your full code/project and I'll have a look.
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    hi

    Code:
    Dim myArray() As String
    Dim intctr As Integer
    
    
    Private Sub Command1_Click()
    intctr = intctr + 1
    ReDim Preserve myArray(intctr, 2)
    End Sub
    Click on the command twice to get the error.

    I think , there is soenthing smalll we are missing....

    Thanks for ur time

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    solved it

    the error was u cannot increment the lower bound in redim i 2D array
    Code:
    Dim myArray() As String
    Dim intctr As Integer
    
    
    Private Sub Command1_Click()
    intctr = intctr + 1
    ReDim Preserve myArray( 2,intctr)
    End Sub

    Would work.

    thanks anyways

  7. #7
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    I think the problem is the

    dim myarray()

    only sets the array up as a 1D dynamic array.

    Let me have a play and get back to you...
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Arbiter - Thanks a lot for your time.

    But see my previous post - I have got the soln - pls do not waste ur time on it.

  9. #9
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    I'm using the following

    VB Code:
    1. Dim myarray() As Integer, x As Integer
    2.  
    3. Private Sub Command1_Click()
    4.     x = x + 1
    5.     ReDim Preserve myarray(1, x)
    6. End Sub
    7.  
    8. Private Sub form_load()
    9.     [b]Dim myarray(0, 0)[/b]
    10. End Sub

    The bit in bold is the bit that I meant you'd need in order to kick the array off
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Works without it as well.

  11. #11
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    Oh, right, yeah.

    I'll shut up now...

    I completely misread your last post anyway.

    I think I need a beer....
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Anyways thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width