PC Review


Reply
Thread Tools Rate Thread

How to assign Spit to 1-origined array?

 
 
Joe User
Guest
Posts: n/a
 
      23rd Dec 2009
Currently, I use Split as follows:

Dim w, mylist as string
w = Split(mylist)

That creates an array with the first index (LBound) of zero.

Is there a straight-forward to cause the first index to be one?

(I don't know the number of "words" in mylist a priori.)

I am using Excel 2003 SP3 with VBA 6.5.1024.
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      24th Dec 2009
No, Split is unusual in that it **always** returns a zero-based array even
if you use "Option Base 1" to force the lower bound of arrays to be one.

--
Rick (MVP - Excel)


"Joe User" <joeu2004> wrote in message
news:(E-Mail Removed)...
> Currently, I use Split as follows:
>
> Dim w, mylist as string
> w = Split(mylist)
>
> That creates an array with the first index (LBound) of zero.
>
> Is there a straight-forward to cause the first index to be one?
>
> (I don't know the number of "words" in mylist a priori.)
>
> I am using Excel 2003 SP3 with VBA 6.5.1024.


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      24th Dec 2009
Well, let my take back the "No" part of my response... you can "fake it" if
you want... just add the delimiter to the front of the text being split...
you will still get a zero-based array, but the zero element will be the
empty string and the first real element will be at index value 1. So, just
change your statement to this...

w = Split(" " & mylist)

where I used a space because Split uses a space as the delimiter by default
when no delimiter is specified. If you were were working with a comma
delimited list, then your statement would be this...

w = Split("," & mylist, ",")

--
Rick (MVP - Excel)


"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> No, Split is unusual in that it **always** returns a zero-based array even
> if you use "Option Base 1" to force the lower bound of arrays to be one.
>
> --
> Rick (MVP - Excel)
>
>
> "Joe User" <joeu2004> wrote in message
> news:(E-Mail Removed)...
>> Currently, I use Split as follows:
>>
>> Dim w, mylist as string
>> w = Split(mylist)
>>
>> That creates an array with the first index (LBound) of zero.
>>
>> Is there a straight-forward to cause the first index to be one?
>>
>> (I don't know the number of "words" in mylist a priori.)
>>
>> I am using Excel 2003 SP3 with VBA 6.5.1024.

>


 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      24th Dec 2009
"Rick Rothstein" <(E-Mail Removed)> wrote:
> No, Split is unusual in that it **always** returns
> a zero-based array


Thanks for the confirmation. No big deal; just curious.


----- original message -----

"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> No, Split is unusual in that it **always** returns a zero-based array even
> if you use "Option Base 1" to force the lower bound of arrays to be one.
>
> --
> Rick (MVP - Excel)
>
>
> "Joe User" <joeu2004> wrote in message
> news:(E-Mail Removed)...
>> Currently, I use Split as follows:
>>
>> Dim w, mylist as string
>> w = Split(mylist)
>>
>> That creates an array with the first index (LBound) of zero.
>>
>> Is there a straight-forward to cause the first index to be one?
>>
>> (I don't know the number of "words" in mylist a priori.)
>>
>> I am using Excel 2003 SP3 with VBA 6.5.1024.

>


 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      24th Dec 2009
"Rick Rothstein" <(E-Mail Removed)> wrote:
> Well, let my take back the "No" part of my response...
> you can "fake it" if you want...

[....]
> w = Split(" " & mylist)


Well, duh! I must be getting old :-).


----- original message -----

"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:e7X7$(E-Mail Removed)...
> Well, let my take back the "No" part of my response... you can "fake it"
> if you want... just add the delimiter to the front of the text being
> split... you will still get a zero-based array, but the zero element will
> be the empty string and the first real element will be at index value 1.
> So, just change your statement to this...
>
> w = Split(" " & mylist)
>
> where I used a space because Split uses a space as the delimiter by
> default when no delimiter is specified. If you were were working with a
> comma delimited list, then your statement would be this...
>
> w = Split("," & mylist, ",")
>
> --
> Rick (MVP - Excel)
>
>
> "Rick Rothstein" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> No, Split is unusual in that it **always** returns a zero-based array
>> even if you use "Option Base 1" to force the lower bound of arrays to be
>> one.
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>> "Joe User" <joeu2004> wrote in message
>> news:(E-Mail Removed)...
>>> Currently, I use Split as follows:
>>>
>>> Dim w, mylist as string
>>> w = Split(mylist)
>>>
>>> That creates an array with the first index (LBound) of zero.
>>>
>>> Is there a straight-forward to cause the first index to be one?
>>>
>>> (I don't know the number of "words" in mylist a priori.)
>>>
>>> I am using Excel 2003 SP3 with VBA 6.5.1024.

>>

>


 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      24th Dec 2009
> ...Split..Is there a straight-forward to cause the first index to be
> one?


Hi. Here's a common workaround that I use:

Sub Demo()
Dim s, v
s = "a,b,c,d,e"
v = Split(s, ",")
v = T2(v)
End Sub


Function T2(v)
'// Double Transpose
With WorksheetFunction
T2 = .Transpose(.Transpose(v))
End With
End Function

= = = = = = = = = = =
HTH :>)
Dana DeLouis



On 12/23/2009 8:19 PM, Joe User wrote:
> "Rick Rothstein" <(E-Mail Removed)> wrote:
>> Well, let my take back the "No" part of my response...
>> you can "fake it" if you want...

> [....]
>> w = Split(" " & mylist)

>
> Well, duh! I must be getting old :-).
>
>
> ----- original message -----
>
> "Rick Rothstein" <(E-Mail Removed)> wrote in message
> news:e7X7$(E-Mail Removed)...
>> Well, let my take back the "No" part of my response... you can "fake
>> it" if you want... just add the delimiter to the front of the text
>> being split... you will still get a zero-based array, but the zero
>> element will be the empty string and the first real element will be at
>> index value 1. So, just change your statement to this...
>>
>> w = Split(" " & mylist)
>>
>> where I used a space because Split uses a space as the delimiter by
>> default when no delimiter is specified. If you were were working with
>> a comma delimited list, then your statement would be this...
>>
>> w = Split("," & mylist, ",")
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>> "Rick Rothstein" <(E-Mail Removed)> wrote in
>> message news:%(E-Mail Removed)...
>>> No, Split is unusual in that it **always** returns a zero-based array
>>> even if you use "Option Base 1" to force the lower bound of arrays to
>>> be one.
>>>
>>> --
>>> Rick (MVP - Excel)
>>>
>>>
>>> "Joe User" <joeu2004> wrote in message
>>> news:(E-Mail Removed)...
>>>> Currently, I use Split as follows:
>>>>
>>>> Dim w, mylist as string
>>>> w = Split(mylist)
>>>>
>>>> That creates an array with the first index (LBound) of zero.
>>>>
>>>> Is there a straight-forward to cause the first index to be one?
>>>>
>>>> (I don't know the number of "words" in mylist a priori.)
>>>>
>>>> I am using Excel 2003 SP3 with VBA 6.5.1024.
>>>

>>

>


 
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
Assign formula array in vba =?Utf-8?B?TWFuT25CYXI=?= Microsoft Excel Programming 0 21st Jul 2005 08:11 PM
Can't assign value to structure in array? Brett Microsoft C# .NET 25 9th Jun 2005 11:49 PM
'Can't Assign to Array' =?Utf-8?B?QW1hbmRhIFBheXRvbg==?= Microsoft Access VBA Modules 3 14th Oct 2004 10:51 PM
How do I assign to an array variable? Hal Heinrich Microsoft VB .NET 3 4th Dec 2003 12:45 PM
Can't Assign to Array XMan Microsoft Access Form Coding 3 4th Nov 2003 08:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:54 PM.