View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban Alan Beban is offline
external usenet poster
 
Posts: 200
Default Arrays - Lower Bound and Singleline Assignment

As you can see, Leo Heuser's code works on a Variant variable to change
it to a String() type array. And it changes it to, for the illustration
you provided, a 3-element 0-based array (and it isn't clear why you
Dimensioned the array at 1 to 20 in the first place when you were ending
up with a smaller array).

But in any event, if the functions in the freely downloadable file at
http:??home.pacbell.net/beban are available to your workbook, you can
work with what you described; this, too, will return a 3-element 0-based
array.

Sub abtest1()
Dim arr() As String 'or As Integer, or whatever, so
'long as the assigned elements
'are of an acceptable type
ReDim arr(1 To 20)
assign Array(1, 2, 3), arr
Debug.Print arr(0), UBound(arr), TypeName(arr)
End Sub

Alan Beban

Leo Heuser wrote:
"Goofy" skrev i en meddelelse
...
Hi,

Is there a way to set the bounds explicitly using the 'To' and then do the
assignment on one line

something like

Dim myArray( 1 to 20 ) as string
myArray = {"one","two","Three"}

??



Hi

If you have Excel 2000 or later, you can use the "Split" function:

Sub test()
Dim MyArray As Variant

MyArray = "One,Two,Three"
MyArray = Split(MyArray, ",")
End Sub

Split *always* return a zero-based array,
even when you do an "Option Base 1"!