|
-
Dec 30th, 2002, 12:31 AM
#1
Thread Starter
Lively Member
array length unknown? adding more to an array? [resolved]
i dont know how to do things with arrays, please help me
im using this code:
Dim sr As StreamReader = File.OpenText("users.txt")
Dim users()() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer = 0
Dim x As Integer = 0
Do While sr.Read
users(x)(0) = sr.ReadLine
users(x)(1) = sr.ReadLine
x += 1
Loop
sr.Close()
End Sub
Dim sr As StreamReader = File.OpenText("users.txt")
Dim users()() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer = 0
Dim x As Integer = 0
Do While sr.Read
users(x)(0) = sr.ReadLine
users(x)(1) = sr.ReadLine
x += 1
Loop
sr.Close()
End Sub
im getting this error:
An unhandled exception of type 'System.NullReferenceException' occurred in first.exe
Additional information: Object reference not set to an instance of an object.
can someone plz help me?
Last edited by joeframbach; Dec 30th, 2002 at 10:06 PM.
if you choose not to decide you still have made a choice!
RUSH rocks!
-
Dec 30th, 2002, 12:50 AM
#2
Fanatic Member
You have to dimension the array before use. Since it is a 2 dimensional array, you can only use Redim on the last index. But, you cannot use Redim on a module level variable.
Why don't you use the ArrayList datatype?
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Dec 30th, 2002, 10:20 AM
#3
Thread Starter
Lively Member
can you tell me more about arraylists? i cant seem to find it in the help index
if you choose not to decide you still have made a choice!
RUSH rocks!
-
Dec 30th, 2002, 10:27 AM
#4
Registered User
Search for "ArrayList Class" in the help and choose the topic with the same name.
-
Dec 30th, 2002, 10:43 AM
#5
Thread Starter
Lively Member
i must be missing something here...
it seems to me that arraylists are not for .net? i get an error: arrays cannot be declared with 'new'.
if you choose not to decide you still have made a choice!
RUSH rocks!
-
Dec 30th, 2002, 02:17 PM
#6
Fanatic Member
You have to reference the System.Collections class and then
try this:
VB Code:
dim myList as new Arraylist
As for help system, do a search on "ArrayList". You should get something even if you have just the .NET SDK and don't have VS.NET
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Dec 30th, 2002, 02:38 PM
#7
Thread Starter
Lively Member
should i put Imports System.Collections at the top, or can i do Dim myList As New System.Collections.ArrayList()
if you choose not to decide you still have made a choice!
RUSH rocks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|