473,472 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

adding items to an arrayList

I'm trying to grab the files in a directory and add each one to an array
list. Thist is what I have:

1 Dim filesToUpload() As ArrayList
2 Dim batchFiles As String() =
System.IO.Directory.GetFiles(Server.MapPath("/batchupload/"))
3 Dim arrayCount As Integer = 0
4 For Each fileName As String In batchFiles
5 filesToUpload(arrayCount).Add(fileName)
6 arrayCount = arrayCount + 1
7 Next

But it's giving me an 'Object reference not set to an instance of an
object.' error on line 5. This is code from a tutorial (though modified to
use an arrayList rather than rediming an array) so I'm assuming I goofed up
my syntax somewhere.

-Darrel
Jun 22 '06 #1
2 1160

I think you need

dim files as ArrayList
files = new ArrayList

You should put in

Option Explicit 'On
Option Strict On

at the top of your code. you'll help yourself out a little bit by now
declaring objects correctly in vb.net


"Darrel" <no*****@nospam.com> wrote in message
news:ej**************@TK2MSFTNGP05.phx.gbl...
I'm trying to grab the files in a directory and add each one to an array
list. Thist is what I have:

1 Dim filesToUpload() As ArrayList
2 Dim batchFiles As String() =
System.IO.Directory.GetFiles(Server.MapPath("/batchupload/"))
3 Dim arrayCount As Integer = 0
4 For Each fileName As String In batchFiles
5 filesToUpload(arrayCount).Add(fileName)
6 arrayCount = arrayCount + 1
7 Next

But it's giving me an 'Object reference not set to an instance of an
object.' error on line 5. This is code from a tutorial (though modified to
use an arrayList rather than rediming an array) so I'm assuming I goofed up my syntax somewhere.

-Darrel

Jun 22 '06 #2
> I think you need

dim files as ArrayList
files = new ArrayList


THanks, sloan. Yes, I NEED to get in the habit of using the option
explicit/strict feature.

-Darrel
Jun 22 '06 #3

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

Similar topics

0
by: Stephen | last post by:
I have been getting on well with help from this forum trying to create an array list and work with it. Everything is working fine apart from displaying my array list items into the labels in my...
11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
2
by: jack | last post by:
Hello, I need to dynamically add menu items to an existing menu on an MDI form. In the form load, when I create the menu items then add it to the menu control using the Add method, the entire...
4
by: blisspikle | last post by:
The following sub form1_load reads in a text file that will say something like the text below. I think that the problem is that every time I add a class V_Sensor into the arraylist it puts it in...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
5
by: Extremest | last post by:
Is there a way to add new items to an arraylist witht he indexer? like with a normal array I can just do like array = new. What I have read with arraylist it will throw an exception if I try to...
3
by: Stuart | last post by:
I am using Visual Basic 2005. I have created a two dimensional ArrayList named aSystem that is populated as follows:- aSystem.Add(New PickList(0, "Undefined")) aSystem.Add(New PickList(-1,...
2
by: wbosw | last post by:
I have a Arraylist (SearchSkillsArray) that contains objects. I want to place those objects into a listbox. Here i'm using get enumerator to loop through the arraylist and add the objects to the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.