+ Reply to Thread
Results 1 to 7 of 7

Initialize an array

  1. #1
    Kleev
    Guest

    Initialize an array

    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)

  2. #2
    Alan Beban
    Guest

    Re: Initialize an array

    Kleev wrote:
    > 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

  3. #3
    Kleev
    Guest

    Re: Initialize an array

    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.

    "Alan Beban" wrote:

    > Kleev wrote:
    > > 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
    >


  4. #4
    Alan Beban
    Guest

    Re: Initialize an array

    Dim descarray()
    ReDim descarray(9)

    Alan Beban

    Kleev wrote:
    > 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.
    >
    > "Alan Beban" wrote:
    >
    >
    >>Kleev wrote:
    >>
    >>>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
    >>


  5. #5
    Kleev
    Guest

    Re: Initialize an array

    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.

    "Alan Beban" wrote:

    > Dim descarray()
    > ReDim descarray(9)
    >
    > Alan Beban
    >
    > Kleev wrote:
    > > 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.
    > >
    > > "Alan Beban" wrote:
    > >
    > >
    > >>Kleev wrote:
    > >>
    > >>>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
    > >>

    >


  6. #6
    Alan Beban
    Guest

    Re: Initialize an array

    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

    Kleev wrote:
    > 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.
    >
    > "Alan Beban" wrote:
    >
    >
    >>Dim descarray()
    >>ReDim descarray(9)
    >>
    >>Alan Beban
    >>
    >>Kleev wrote:
    >>
    >>>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.
    >>>
    >>>"Alan Beban" wrote:
    >>>
    >>>
    >>>
    >>>>Kleev wrote:
    >>>>
    >>>>
    >>>>>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
    >>>>

    >>


  7. #7
    Kleev
    Guest

    Re: Initialize an array

    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.)

    "Alan Beban" wrote:

    > 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
    >
    > Kleev wrote:
    > > 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.
    > >
    > > "Alan Beban" wrote:
    > >
    > >
    > >>Dim descarray()
    > >>ReDim descarray(9)
    > >>
    > >>Alan Beban
    > >>
    > >>Kleev wrote:
    > >>
    > >>>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.
    > >>>
    > >>>"Alan Beban" wrote:
    > >>>
    > >>>
    > >>>
    > >>>>Kleev wrote:
    > >>>>
    > >>>>
    > >>>>>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
    > >>>>
    > >>

    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1