Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Arrays - Lower Bound and Singleline Assignment

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"}

??


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 266
Default Arrays - Lower Bound and Singleline Assignment

"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"!

--
Best regards
Leo Heuser

Followup to newsgroup only please.


  #3   Report Post  
Posted to microsoft.public.excel.programming
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"!

Reply
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
Change from mixed caps and upper lower to all upper lower case Fish''s Mermaid Excel Worksheet Functions 3 October 13th 06 02:15 PM
Forms, Bound Columns etc Michael Beckinsale Excel Programming 1 March 24th 06 10:49 AM
Data bound VBA forms Andy Excel Programming 2 September 14th 04 04:49 PM
Cell Bound Combo Box Adrian Soper Excel Programming 1 June 7th 04 01:59 PM
Listbox with Bound Columns Vijay Bhatawdekar Excel Programming 0 February 11th 04 07:47 AM


All times are GMT +1. The time now is 11:01 PM.

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"