Adding Index Number to a Dynamic Array

Discussion in 'ASP General' started by Brian Piotrowski, Apr 6, 2006.

  1. Hi All,

    I've probably done this before, but for the life of me I can't remember how
    I did it. I need to move values from a DB table into an array to be used
    for other queries. The number of records will vary, so I need to make the
    array dynamic. Can someone remind me how I can increment the index when I
    write a new record? Here's a sample of the code I wrote:

    If rsGETKD.EOF = False Then
    Dim KDLOTSQ
    KDLOTSQ = rsGETKD.GetRows()
    iRecFirst = LBound(KDLOTSQ, 2)
    iRecLast = UBound(KDLOTSQ, 2)
    iFieldFirst = LBound(KDLOTSQ, 1)
    iFieldLast = UBound(KDLOTSQ, 1)
    Dim KDLTable
    MyCount = 0
    For I = iRecFirst To iRecLast
    MyText=""
    For J = iFieldFirst To iFieldLast
    MyText=MyText & KDLOTSQ(J, I)
    Next
    KDLTable(MyCount) = MyText
    MyCount = MyCount + 1
    Next
    End If

    What this code is supposed to do is read a DB table that contains two
    values. These two values are written to another array (KDLTable) that I can
    use as a reference later on in my ASP (I need to read this table four times
    at four different record locations).

    When I run this code, I get an "800a000d Type Mismatch" Error. Looking at
    the code, the program breaks at "KDLTable(MyCount) = MyText". I'm sure the
    program is failing when the system tries to use MyCount as the index number.

    How can I increment the index number for each value in the table? For
    example, if there are three records in the table, (ABC123, DEF456 and
    GHI789), I would like to write in this manner:

    KDLTable(0) = ABC123
    KDLTable(1) = DEF456
    KDLTable(2) = GHI789

    Any ideas would be appreciated.

    Thanks!

    Brian.
     
    Brian Piotrowski, Apr 6, 2006
    #1
    1. Advertising

  2. Brian Piotrowski

    Slim Guest

    dim myArr()

    redim preserve myArray(N)

    myArray(N) = "value"




    "Brian Piotrowski" <> wrote in message
    news:...
    > Hi All,
    >
    > I've probably done this before, but for the life of me I can't remember
    > how I did it. I need to move values from a DB table into an array to be
    > used for other queries. The number of records will vary, so I need to
    > make the array dynamic. Can someone remind me how I can increment the
    > index when I write a new record? Here's a sample of the code I wrote:
    >
    > If rsGETKD.EOF = False Then
    > Dim KDLOTSQ
    > KDLOTSQ = rsGETKD.GetRows()
    > iRecFirst = LBound(KDLOTSQ, 2)
    > iRecLast = UBound(KDLOTSQ, 2)
    > iFieldFirst = LBound(KDLOTSQ, 1)
    > iFieldLast = UBound(KDLOTSQ, 1)
    > Dim KDLTable
    > MyCount = 0
    > For I = iRecFirst To iRecLast
    > MyText=""
    > For J = iFieldFirst To iFieldLast
    > MyText=MyText & KDLOTSQ(J, I)
    > Next
    > KDLTable(MyCount) = MyText
    > MyCount = MyCount + 1
    > Next
    > End If
    >
    > What this code is supposed to do is read a DB table that contains two
    > values. These two values are written to another array (KDLTable) that I
    > can use as a reference later on in my ASP (I need to read this table four
    > times at four different record locations).
    >
    > When I run this code, I get an "800a000d Type Mismatch" Error. Looking at
    > the code, the program breaks at "KDLTable(MyCount) = MyText". I'm sure
    > the program is failing when the system tries to use MyCount as the index
    > number.
    >
    > How can I increment the index number for each value in the table? For
    > example, if there are three records in the table, (ABC123, DEF456 and
    > GHI789), I would like to write in this manner:
    >
    > KDLTable(0) = ABC123
    > KDLTable(1) = DEF456
    > KDLTable(2) = GHI789
    >
    > Any ideas would be appreciated.
    >
    > Thanks!
    >
    > Brian.
    >
     
    Slim, Apr 6, 2006
    #2
    1. Advertising

  3. In this case, what is (N) equal to? How do I increase the value of the
    index number when I read a new record? Is the REDIM statement within the
    next loop for the recordset?

    "Slim" <> wrote in message
    news:%...
    > dim myArr()
    >
    > redim preserve myArray(N)
    >
    > myArray(N) = "value"
    >
    >
    >
    >
    > "Brian Piotrowski" <> wrote in message
    > news:...
    >> Hi All,
    >>
    >> I've probably done this before, but for the life of me I can't remember
    >> how I did it. I need to move values from a DB table into an array to be
    >> used for other queries. The number of records will vary, so I need to
    >> make the array dynamic. Can someone remind me how I can increment the
    >> index when I write a new record? Here's a sample of the code I wrote:
    >>
    >> If rsGETKD.EOF = False Then
    >> Dim KDLOTSQ
    >> KDLOTSQ = rsGETKD.GetRows()
    >> iRecFirst = LBound(KDLOTSQ, 2)
    >> iRecLast = UBound(KDLOTSQ, 2)
    >> iFieldFirst = LBound(KDLOTSQ, 1)
    >> iFieldLast = UBound(KDLOTSQ, 1)
    >> Dim KDLTable
    >> MyCount = 0
    >> For I = iRecFirst To iRecLast
    >> MyText=""
    >> For J = iFieldFirst To iFieldLast
    >> MyText=MyText & KDLOTSQ(J, I)
    >> Next
    >> KDLTable(MyCount) = MyText
    >> MyCount = MyCount + 1
    >> Next
    >> End If
    >>
    >> What this code is supposed to do is read a DB table that contains two
    >> values. These two values are written to another array (KDLTable) that I
    >> can use as a reference later on in my ASP (I need to read this table four
    >> times at four different record locations).
    >>
    >> When I run this code, I get an "800a000d Type Mismatch" Error. Looking
    >> at the code, the program breaks at "KDLTable(MyCount) = MyText". I'm
    >> sure the program is failing when the system tries to use MyCount as the
    >> index number.
    >>
    >> How can I increment the index number for each value in the table? For
    >> example, if there are three records in the table, (ABC123, DEF456 and
    >> GHI789), I would like to write in this manner:
    >>
    >> KDLTable(0) = ABC123
    >> KDLTable(1) = DEF456
    >> KDLTable(2) = GHI789
    >>
    >> Any ideas would be appreciated.
    >>
    >> Thanks!
    >>
    >> Brian.
    >>

    >
    >
     
    Brian Piotrowski, Apr 6, 2006
    #3
  4. Nevermind, I see what you meant. Thanks, Slim.


    "Slim" <> wrote in message
    news:%...
    > dim myArr()
    >
    > redim preserve myArray(N)
    >
    > myArray(N) = "value"
    >
    >
    >
    >
    > "Brian Piotrowski" <> wrote in message
    > news:...
    >> Hi All,
    >>
    >> I've probably done this before, but for the life of me I can't remember
    >> how I did it. I need to move values from a DB table into an array to be
    >> used for other queries. The number of records will vary, so I need to
    >> make the array dynamic. Can someone remind me how I can increment the
    >> index when I write a new record? Here's a sample of the code I wrote:
    >>
    >> If rsGETKD.EOF = False Then
    >> Dim KDLOTSQ
    >> KDLOTSQ = rsGETKD.GetRows()
    >> iRecFirst = LBound(KDLOTSQ, 2)
    >> iRecLast = UBound(KDLOTSQ, 2)
    >> iFieldFirst = LBound(KDLOTSQ, 1)
    >> iFieldLast = UBound(KDLOTSQ, 1)
    >> Dim KDLTable
    >> MyCount = 0
    >> For I = iRecFirst To iRecLast
    >> MyText=""
    >> For J = iFieldFirst To iFieldLast
    >> MyText=MyText & KDLOTSQ(J, I)
    >> Next
    >> KDLTable(MyCount) = MyText
    >> MyCount = MyCount + 1
    >> Next
    >> End If
    >>
    >> What this code is supposed to do is read a DB table that contains two
    >> values. These two values are written to another array (KDLTable) that I
    >> can use as a reference later on in my ASP (I need to read this table four
    >> times at four different record locations).
    >>
    >> When I run this code, I get an "800a000d Type Mismatch" Error. Looking
    >> at the code, the program breaks at "KDLTable(MyCount) = MyText". I'm
    >> sure the program is failing when the system tries to use MyCount as the
    >> index number.
    >>
    >> How can I increment the index number for each value in the table? For
    >> example, if there are three records in the table, (ABC123, DEF456 and
    >> GHI789), I would like to write in this manner:
    >>
    >> KDLTable(0) = ABC123
    >> KDLTable(1) = DEF456
    >> KDLTable(2) = GHI789
    >>
    >> Any ideas would be appreciated.
    >>
    >> Thanks!
    >>
    >> Brian.
    >>

    >
    >
     
    Brian Piotrowski, Apr 6, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PhilC
    Replies:
    4
    Views:
    357
    PhilC
    Oct 30, 2004
  2. Josselin
    Replies:
    3
    Views:
    119
    Josselin
    Jun 2, 2007
  3. Shawn W_
    Replies:
    5
    Views:
    284
    Aldric Giacomoni
    Sep 16, 2009
  4. Jeff Dik
    Replies:
    8
    Views:
    174
    Robert Klemme
    Mar 30, 2011
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    298
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page