473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Error populating array

Can someone please help me out?

I have a dataset that contains 1 column.
I'm trying to populate an array from this column.
I'm using the code pasted below, and keep getting the following error on the
4th line of code:

Object reference not set to an instance of an object.

Dim arr() As String
Dim j As Integer = 0
For Each row As DataRow In _ds2.Tables(0).Rows

arr(j) = row(0).ToString
j = j + 1

Next

TIA,
Amber
Sep 24 '05 #1
2 1444
For Each row As DataRow In _ds2.Tables(0).Rows
Redim Preserve arr(j)
arr(j) = row(0).ToString
j = j + 1
Next

But why not using an arraylist

Dim l_arr as ArrayList
l_arr=New ArrayList(_ds2.Tables(0).Rows.Count)
'l_arr=New ArrayList() is oke too, your arraylist shall then dynamicly be
resized
For Each row As DataRow In _ds2.Tables(0).Rows
l_arr.Add(row(0).ToString)
Next
"amber" <am***@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.com...
Can someone please help me out?

I have a dataset that contains 1 column.
I'm trying to populate an array from this column.
I'm using the code pasted below, and keep getting the following error on
the
4th line of code:

Object reference not set to an instance of an object.

Dim arr() As String
Dim j As Integer = 0
For Each row As DataRow In _ds2.Tables(0).Rows

arr(j) = row(0).ToString
j = j + 1

Next

TIA,
Amber

Sep 24 '05 #2
Instead of using ReDim Preserve on every iteration, just use ReDim once prior
to entering the loop - it's much faster. (unless you decide to use ArrayList
of course).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code
"Roel Oost" wrote:
For Each row As DataRow In _ds2.Tables(0).Rows
Redim Preserve arr(j)
arr(j) = row(0).ToString
j = j + 1
Next

But why not using an arraylist

Dim l_arr as ArrayList
l_arr=New ArrayList(_ds2.Tables(0).Rows.Count)
'l_arr=New ArrayList() is oke too, your arraylist shall then dynamicly be
resized
For Each row As DataRow In _ds2.Tables(0).Rows
l_arr.Add(row(0).ToString)
Next
"amber" <am***@discussions.microsoft.com> wrote in message
news:07**********************************@microsof t.com...
Can someone please help me out?

I have a dataset that contains 1 column.
I'm trying to populate an array from this column.
I'm using the code pasted below, and keep getting the following error on
the
4th line of code:

Object reference not set to an instance of an object.

Dim arr() As String
Dim j As Integer = 0
For Each row As DataRow In _ds2.Tables(0).Rows

arr(j) = row(0).ToString
j = j + 1

Next

TIA,
Amber


Sep 25 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lukelrc | last post by:
Hi, I have some VBscript that lists the files in a folder. What i want to do is populate an array with the file names and then use that array to populate a list box. I have got as far as...
2
by: amber | last post by:
Can someone please help me out? I have a dataset that contains 1 column. I'm trying to populate an array from this column. I'm using the code pasted below, and keep getting the following error...
0
by: smlemmon | last post by:
Hi, This is my first post, but have been an avid reader up until to now. Great resource though. Anyway, onto my problem. I need to use the Microsoft.VisualBasic.Financial.IRR procedure in my...
0
by: jac130 | last post by:
i need to populate an array with grades. there is an 'add students & grades' button. user is prompted by input box to enter a students name, then another input box to enter their grade. the student's...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.