|
-
Feb 25th, 2008, 07:51 AM
#14
Thread Starter
New Member
Re: [2008] Reading from a txt file
The error is unhandled expception, object reference not set to an instance of an object.
Okay, I'm fairly close now after experimenting awhile, everything runs fine, but out of some weird reason it fetches one line too much. For example if I want to print out NPpw(2) it would print out test3 (from the third line)
Here's my code
vb Code:
Dim FILE_NAME As String = String.Empty Dim TempArray() As String Dim i As Integer = 1 If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then ' If file exists, then go on FILE_NAME = OpenFileDialog1.FileName End If Dim tempLine() As String = IO.File.ReadAllLines(FILE_NAME) Dim NPuser(tempLine.Length - 1) As String Dim NPpw(tempLine.Length - 1) As String For i = 1 To tempLine.GetUpperBound(0) TempArray = tempLine(i).Trim.Split("/"c) NPuser(i) = TempArray(0) NPpw(i) = TempArray(1) TempArray = Nothing Next i MsgBox(NPuser(2) & " " & NPpw(2)) End Sub
Okay I kind of realized the reason for this happening, and it's because the first line is stored in (0), but yeah.. is there any way to fix this? So that the lines are stored in the correct order
Last edited by Spacey; Feb 25th, 2008 at 08:28 AM.
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
|