Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Not exactly. That's true for arrays of type other than Variant(). But
you *can* "assign" the dimensionality of a Variant() array, first by declaring it as a dynamic array, then fixing the dimensionality, a la Option Base 1 _____________________ Sub test1() Dim strA() As Variant ReDim strA(1 to 5) strA = Array("a", "b", "c", "d", "e") MsgBox strA(1) & " " & strA(5) '<---displays a e End Sub As I mentioned in a previous post in this thread, you can avoid the 0-base by using the Option Base 1 statement at the beginning of your code module. By the way, I don't know what logic you're intending to impose, but I don't find anything illogical about a zeroth index, nor, for that matter, negative indexes. They're just indexes, after all. Dim strA(-2 to 3) declares a 1-dimensional array with lower bound -2, upper bound 3, and, once loaded, elements accessible by strA(-2) strA(-1) strA(0) strA(1) strA(2) strA(3) Alan Beban MWE < wrote: Bob: thanks for the reply about using the Array function. I have tried to use it in the past and it never worked. I now understand that you can not define the dimenionality of the variable nor can you define its type. So: Sub TestArrayFill() ' ' procedure to test the use of the Array function ' Dim strA(1 to 5) as String strA = Array("a", "b", "c", "d", "e") MsgBox strA(1) + " " + strA(5) End Sub generates compiler errors as does any other code that defines the scope of strA or its type. I can see where the use of Array would be useful, but it bothers me that it is so vague and it encourages bad code. It also forces the use of zero as the first index which I find irksome. Logically there is no such thing as a zeroth index. I understand why it is there -- makes things more compact -- but it bugs me none the less. Is there nothing that will allow me to "fill and array" that has been previously scoped and types. Seems like a very reasonable thing to want. Thanks MWE --- Message posted from http://www.ExcelForum.com/ |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Assigning values to a variable set | Excel Discussion (Misc queries) | |||
Assigning percentage values? | Excel Discussion (Misc queries) | |||
Assigning Values to Symbols | Excel Discussion (Misc queries) | |||
Assigning point values? | Excel Worksheet Functions | |||
Assigning values to letters | Excel Worksheet Functions |