Initialize an array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to initialize an array the same way you can initialize a
Variant? If so, what is the syntax? I tried to dim an array and make it
equal to an array as below, but could not get it to work. Thanks.

Dim DescArray As Variant, TrackColArray As Variant, ReportColArray As Variant


DescArray = Array("Type", "Store", "Name", "FDO", "GO Weekend", "SS
Groom", _
"Grooming", "DDC", "Phone")
TrackColArray = Array(1, 3, 4, 5, 6, 7, 8, 9, 12)
ReportColArray = Array(1, 2, 4, 5, 6, 7, 8, 9, 10)
 
Kleev said:
Is there a way to initialize an array the same way you can initialize a
Variant? If so, what is the syntax? I tried to dim an array and make it
equal to an array as below, but could not get it to work. Thanks.

Dim DescArray As Variant, TrackColArray As Variant, ReportColArray As Variant


DescArray = Array("Type", "Store", "Name", "FDO", "GO Weekend", "SS
Groom", _
"Grooming", "DDC", "Phone")
TrackColArray = Array(1, 3, 4, 5, 6, 7, 8, 9, 12)
ReportColArray = Array(1, 2, 4, 5, 6, 7, 8, 9, 10)
What do you mean "could not get it to work." What happens? It works
fine if you break your lines at the right point with appropriate
continuation characters. E.g.,

DescArray = Array("Type", "Store", "Name", "FDO", "GO Weekend", _
"SS Groom", "Grooming", "DDC", "Phone")
TrackColArray = Array(1, 3, 4, 5, 6, 7, 8, 9, 12)
ReportColArray = Array(1, 2, 4, 5, 6, 7, 8, 9, 10)

Alan Beban
 
Sorry. Yes this works fine. What I mean is change the dim statements to
refer to arrays not variants. ie
dim descarray(9)
and then try the following. I cannot get it to work.

Sorry about the original phrasing. Once I posted it, I realized it was open
to interpretation.
 
Dim descarray()
ReDim descarray(9)

Alan Beban
Sorry. Yes this works fine. What I mean is change the dim statements to
refer to arrays not variants. ie
dim descarray(9)
and then try the following. I cannot get it to work.

Sorry about the original phrasing. Once I posted it, I realized it was open
to interpretation.

:
 
That did work and I thank you for the answer. I, however, made another
mistake. As soon as I posted my last reply, I realized that the way I had
dimmed descarray was not quite complete. I should have written dim
descarray(9) as string.

Since I cannot get it to work other than as a Variant, I will just use that.
It was just that I had heard so much about using Variants only when
absolutely necessary, I would try to dimension the array as the correct type.

Thanks.
 
If the functions in the freely downloadable file at
http://home.pacbell.net/beban are available to your workbook

Dim DescArray() As String
ReDim DescArray(9)
Assign Array("Type", "Store", "Name", "FDO", "GO Weekend", _
"SS Groom", "Grooming", "DDC", "Phone"), DescArray

Alan Beban
 
Thanks. That answers my question. You would not have needed to write a
function had the syntax in VBA allowed what I was asking without it
(convoluted, but hopefully you know what I mean.)

I don't believe I can use your function as I am at a work computer and don't
believe they would want me to enable someone else's macros. I would have
liked to look at it, but when I answered no to enabling macros, I was not
able to see the macros (not sure if I would have regardless of how I answered
that prompt.)
 
Back
Top