ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Explain some things please (https://www.excelbanter.com/excel-programming/360579-explain-some-things-please.html)

Mike

Explain some things please
 
Looking at the code below, what do some of these mea? Like ReDim and ReDim
Preserve? And v(i). Is this a variable, and if so, why the i in parens?

ReDim v(0 To 0)

ReDim Preserve v(0 To i)

v(i) = "State" & Right(ctrl.Name, 1)

ActiveSheet.Shapes.Range(v).Select




Ivan Raiminius

Explain some things please
 
Hi Mike,

see help for using arrays, should give you appropriate answers.

Regards,
Ivan


Tom Ogilvy

Explain some things please
 
Why not highlight the code in the VBE and hit F1.

--
Regards,
Tom Ogilvy


"Mike" wrote:

Looking at the code below, what do some of these mea? Like ReDim and ReDim
Preserve? And v(i). Is this a variable, and if so, why the i in parens?

ReDim v(0 To 0)

ReDim Preserve v(0 To i)

v(i) = "State" & Right(ctrl.Name, 1)

ActiveSheet.Shapes.Range(v).Select




Mike

Explain some things please
 
I have tried this and was looking for a simpler explanation. Plus, it doesn't
say anything about Preserve that I saw, or why you have (0 To 0) for ReDim.
Thanks anyways.

"Mike" wrote:

Looking at the code below, what do some of these mea? Like ReDim and ReDim
Preserve? And v(i). Is this a variable, and if so, why the i in parens?

ReDim v(0 To 0)

ReDim Preserve v(0 To i)

v(i) = "State" & Right(ctrl.Name, 1)

ActiveSheet.Shapes.Range(v).Select




Tom Ogilvy

Explain some things please
 
If you highlighted redim and hit F1, it has all kinds of information on
Preserve.

Dim v() as Variant

declares v as a dynamic array of type variant.

Redim v(0 to 0)
initializes v to by a one dimensonal array with a lower bound of zero and an
upperbound of zero (therefore it is one element)

redim Preserve v(0 to i)
redimensions the array v (while preserving it existing content) to have a
lower bound of zero and an upper bound of the value in the variable i so it
has

i - 0 + 1 elements or i + 1 elements.

--
Regards,
Tom Ogilvy


"Mike" wrote:

I have tried this and was looking for a simpler explanation. Plus, it doesn't
say anything about Preserve that I saw, or why you have (0 To 0) for ReDim.
Thanks anyways.

"Mike" wrote:

Looking at the code below, what do some of these mea? Like ReDim and ReDim
Preserve? And v(i). Is this a variable, and if so, why the i in parens?

ReDim v(0 To 0)

ReDim Preserve v(0 To i)

v(i) = "State" & Right(ctrl.Name, 1)

ActiveSheet.Shapes.Range(v).Select





All times are GMT +1. The time now is 01:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com