Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Adding Index Number to a Dynamic Array

Reply
Thread Tools

Adding Index Number to a Dynamic Array

 
 
Brian Piotrowski
Guest
Posts: n/a
 
      04-06-2006
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.


 
Reply With Quote
 
 
 
 
Slim
Guest
Posts: n/a
 
      04-06-2006
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.
>



 
Reply With Quote
 
 
 
 
Brian Piotrowski
Guest
Posts: n/a
 
      04-06-2006
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.
>>

>
>



 
Reply With Quote
 
Brian Piotrowski
Guest
Posts: n/a
 
      04-06-2006
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.
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Why can a floating point number be used as an array index? Jeff Dik Ruby 8 03-30-2011 09:15 AM
Making an array wrap, where last index + 1 = first index Shawn W_ Ruby 5 09-16-2009 02:45 PM
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
Array index of first bigger number... Josselin Ruby 3 06-02-2007 09:23 AM
Finding the array index number for known content. PhilC Python 4 10-30-2004 04:11 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57