LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 171
Default Assigning Array Values

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning values to a variable set John A[_2_] Excel Discussion (Misc queries) 1 April 23rd 10 08:20 PM
Assigning percentage values? BFrancis Excel Discussion (Misc queries) 1 November 25th 09 06:35 PM
Assigning Values to Symbols George Excel Discussion (Misc queries) 6 September 6th 07 09:03 PM
Assigning point values? Riptide Excel Worksheet Functions 2 July 23rd 07 12:54 PM
Assigning values to letters Cheri Excel Worksheet Functions 3 December 20th 05 03:55 AM


All times are GMT +1. The time now is 06:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"