Results 1 to 5 of 5

Redim Preserve a multi-dimen. array.

Threaded View

david90 Redim Preserve a multi-dimen.... 10-07-2012, 07:31 PM
Leith Ross Re: Redim Preserve a... 10-07-2012, 08:31 PM
david90 Re: Redim Preserve a... 10-08-2012, 02:36 PM
mike7952 Re: Redim Preserve a... 10-08-2012, 03:33 PM
Norie Re: Redim Preserve a... 10-08-2012, 03:41 PM
  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    oc,ca
    MS-Off Ver
    Excel 2003
    Posts
    44

    Redim Preserve a multi-dimen. array.

    When I execute the code below, the value of the "element" variable at the last line equals to 1 instead of 3. Can somebody tell me why?

    The variable "element" at the last line would equals to 3 if I don't use the preserve keyword with the redim statement.

    Sub test()
    On Error Resume Next
    Dim array1() As String
    Dim element As Integer
    
    element = 0
    ReDim Preserve array1(element + 1, 1)
    element = UBound(array1, 1)
    
    element = element + 1
    
    ReDim Preserve array1(element, 1)
    element = UBound(array1, 1)
    
    element = element + 1
    
    ReDim Preserve array1(element, 1)
    element = UBound(array1, 1)
    
    End Sub
    Last edited by Leith Ross; 10-07-2012 at 08:28 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1