+ Reply to Thread
Results 1 to 8 of 8

ReDim v(UBound(b) - (UBound(b) < 0), 1)

  1. #1
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    ReDim v(UBound(b) - (UBound(b) < 0), 1)

    Hi everybody!

    I can't understand the meaning of this line
    Please Login or Register  to view this content.
    ! I'm a beginner and never saw that before and can't find it on the internet!
    In this part of code:

    Please Login or Register  to view this content.
    Thank you very much!

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: ReDim v(UBound(b) - (UBound(b) < 0), 1)

    Arrays in VBA can have a 'Base' of 0 or 1. The base is simply the default first element of an array. For example you would not want an array starting at 0 if you were stepping through an array and storing row data using the array element number, there is no Row 0.

    The default array base is set using the
    Please Login or Register  to view this content.
    statements at the top of the module. These only affect the module they are declared in.

    The code is simply to take account of the Base settings when re-dimming an array. You can see the effects with the following code. Add to a new module, include the Base 0 statement at the top and copy
    Please Login or Register  to view this content.
    Use F8 to step through the code and have the Immediate (Ctrl-G) window open to see the results.

    Change the Option Base statement to 1 and step through it again - the results will be different.
    Last edited by cytop; 05-21-2016 at 06:23 AM.

  3. #3
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: ReDim v(UBound(b) - (UBound(b) < 0), 1)

    Thank you very much for your answer!
    Now I understood the general "information".
    But I still have a question, what does it mean
    Please Login or Register  to view this content.
    ?
    Please Login or Register  to view this content.
    is the length of table "b" if I don't make mistake... But I don't understand
    Please Login or Register  to view this content.
    ? And how can we subtract this expression? It doesn't make sense for me!...
    Sorry for my English! And thank you!

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: ReDim v(UBound(b) - (UBound(b) < 0), 1)

    (UBound(b) < 0) returns True if the upper bound of b is < 0, else False.

    When a Boolean is part of an arithmetic operation, True is coerced to -1 and False to 0.

    So ReDim v (UBound(b) − (UBound(b) < 0) , ...) sizes the first dimension of v to be either the same as UBound(b) if UBound(b) >=0, or one greater if the UBound(b) is < 0.

    The rationale for doing so doesn't appear in the code.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: ReDim v(UBound(b) - (UBound(b) < 0), 1)

    hi! Thank you for your answer!
    I understand now! But how the upper bound of a table can be <0? And when I try the example of @cytop I find the same result ether I use
    Please Login or Register  to view this content.
    or that
    Please Login or Register  to view this content.
    ! Sorry I'm just starting with vba!

  6. #6
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: ReDim v(UBound(b) - (UBound(b) < 0), 1)

    If I can have further explications thank you very much!

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: ReDim v(UBound(b) - (UBound(b) < 0), 1)

    how the upper bound of a table can be <0?
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-08-2016
    Location
    France
    MS-Off Ver
    2013
    Posts
    58

    Re: ReDim v(UBound(b) - (UBound(b) < 0), 1)

    Thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Dim/Redim/Ubound Explanation
    By jsmilke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-17-2014, 06:29 PM
  2. [SOLVED] ReDim/UBound Eplanation
    By jsmilke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2014, 05:41 PM
  3. ReDim Y(1 To UBound(X, 1) * UBound(X, 2), 1 To 8)
    By sohaila in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2014, 05:48 PM
  4. [SOLVED] UBound and LBound
    By jonathan.haynes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2013, 05:55 AM
  5. [SOLVED] LBound/UBound Intersect together
    By janulikb in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-21-2013, 05:41 AM
  6. Ubound and Lbound
    By hommer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-21-2010, 11:58 AM
  7. [SOLVED] resize(Ubound, Lbound)
    By ina in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2006, 10:00 AM
  8. Array Ubound
    By gti_jobert in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-27-2006, 05:40 PM

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