PC Review


Reply
Thread Tools Rate Thread

Arrays - Lower Bound and Singleline Assignment

 
 
Goofy
Guest
Posts: n/a
 
      2nd Nov 2006
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"}

??


 
Reply With Quote
 
 
 
 
Leo Heuser
Guest
Posts: n/a
 
      2nd Nov 2006
"Goofy" <(E-Mail Removed)> skrev i en meddelelse
news:uyzeuDm$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Alan Beban
Guest
Posts: n/a
 
      2nd Nov 2006
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" <(E-Mail Removed)> skrev i en meddelelse
> news:uyzeuDm$(E-Mail Removed)...
>> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format changes going across whole document rather than just a singleline GB Microsoft Outlook Discussion 0 29th May 2008 03:32 PM
Rule to recall collection lower bound index ? Michel S. Microsoft Excel Programming 1 17th Feb 2007 06:23 PM
Bug with Array.CreateInstance() when lower bound > 0 Gianluca Microsoft C# .NET 2 19th Nov 2006 09:24 PM
How to get the coordinate of the lower-bound cell in Excel 2003 with C# zlf Microsoft Excel Discussion 6 5th Jul 2005 06:15 PM
Newbie confusion on assignment, references, pointers, arrays.. Russ Microsoft C# .NET 7 29th Jun 2004 04:19 AM


Features
 

Advertising
 

Newsgroups
 


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