Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Fill an Array with String values

Simple question. How do I load a list of strings into an array?

I know I code so the following but it seems inefficient.

Dim a (1 to 20) as String

a(1) = "String1"
a(2) = "String2"
etc...

Can I do something like...

a(1 to 20) = "String1", "String2", "String3" ....."String20"

or

a = Array("String1", "String2", "String3" ....."String20" )

Thanks.

- John Michl
www.JohnMichl.com


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Fill an Array with String values

John,

Dim a

a = Array("String1", "String2", "String3" ....."String20" )

Don't pre-dimension it.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Michl" wrote in message
...
Simple question. How do I load a list of strings into an array?

I know I code so the following but it seems inefficient.

Dim a (1 to 20) as String

a(1) = "String1"
a(2) = "String2"
etc...

Can I do something like...

a(1 to 20) = "String1", "String2", "String3" ....."String20"

or

a = Array("String1", "String2", "String3" ....."String20" )

Thanks.

- John Michl
www.JohnMichl.com




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Fill an Array with String values

For 20 values, I am not sure the individual assignment approach is
particularly costly.

Option Explicit

Sub main()
Dim v As Variant, i As Integer
v = Split("abc,def,ghi,jkl", ",")
Debug.Print "------------"
For i = LBound(v) To UBound(v)
Debug.Print v(i)
Next
Debug.Print "------------"
v = Array("mno", "pqr", "stu", "vwx")
For i = LBound(v) To UBound(v)
Debug.Print v(i)
Next
End Sub


"John Michl" wrote in message
...
Simple question. How do I load a list of strings into an array?

I know I code so the following but it seems inefficient.

Dim a (1 to 20) as String

a(1) = "String1"
a(2) = "String2"
etc...

Can I do something like...

a(1 to 20) = "String1", "String2", "String3" ....."String20"

or

a = Array("String1", "String2", "String3" ....."String20" )

Thanks.

- John Michl
www.JohnMichl.com




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Fill an Array with String values

You can do one of a number of things. E.g.:

Dim a
a = Array("String1", "String2", "String3")

a will seem to be an Array of type Variant() [i.e., that's what
Typename(a) will return], though many (most?) people describe it as a
Variant variable containing an array of strings. Nevertheless,
If TypeName(a) = "Variant" Then
MsgBox "Variant variable"
Else
MsgBox "Variant array"
End If

will display Variant array.

In current versions, xl2000 and later, you can use

Dim a()
a = Array("String1", "String2", "String3" ....."String20")
Once again, Typename(a) will return Variant()

If the functions in the file at http://home.pacbell.net/beban are
available to your workbook, you can use

Dim a() As String
Assign Array("String1", "String2", "String3"), a

in which case a will be an array of type String()

Alan Beban

John Michl wrote:

Simple question. How do I load a list of strings into an array?

I know I code so the following but it seems inefficient.

Dim a (1 to 20) as String

a(1) = "String1"
a(2) = "String2"
etc...

Can I do something like...

a(1 to 20) = "String1", "String2", "String3" ....."String20"

or

a = Array("String1", "String2", "String3" ....."String20" )

Thanks.

- John Michl
www.JohnMichl.com


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Fill an Array with String values

For those who don't like loops per say, here is a "Poor mans" version of
List processing...

Sub Demo()
'// Dana DeLouis
Dim v
v = [Transpose("String" & Row(A1:A20))]
End Sub

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"John Michl" wrote in message
...
Simple question. How do I load a list of strings into an array?

I know I code so the following but it seems inefficient.

Dim a (1 to 20) as String

a(1) = "String1"
a(2) = "String2"
etc...

Can I do something like...

a(1 to 20) = "String1", "String2", "String3" ....."String20"

or

a = Array("String1", "String2", "String3" ....."String20" )

Thanks.

- John Michl
www.JohnMichl.com






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Fill an Array with String values

Dana DeLouis wrote:
For those who don't like loops per say, here is a "Poor mans" version of
List processing...

Sub Demo()
'// Dana DeLouis
Dim v
v = [Transpose("String" & Row(A1:A20))]
End Sub


or v = ["String" & Column(A1:T1)]

Alan Beban
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Fill an Array with String values

Or v = ["String" & Column(A:T)]

---
Regards,
Norman Jones

"Alan Beban" wrote in message
...
Dana DeLouis wrote:
For those who don't like loops per say, here is a "Poor mans" version of
List processing...

Sub Demo()
'// Dana DeLouis
Dim v
v = [Transpose("String" & Row(A1:A20))]
End Sub


or v = ["String" & Column(A1:T1)]

Alan Beban



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
last number array from string Michael Excel Worksheet Functions 17 August 1st 05 07:30 PM
Variant Array with String Values - Type Mismatch jamiee Excel Programming 2 March 7th 04 03:39 AM
String to Array Conversion Ussiddiqui[_14_] Excel Programming 1 January 31st 04 10:04 AM
Convert a string to an array Dana DeLouis[_5_] Excel Programming 0 September 30th 03 04:02 AM
Convert a string to an array don Excel Programming 0 September 29th 03 05:08 PM


All times are GMT +1. The time now is 11:20 AM.

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

About Us

"It's about Microsoft Excel"