Results 1 to 16 of 16

Thread: [RESOLVED] [2008] Reading from a txt file

Threaded View

  1. #14

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    12

    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:
    1. Dim FILE_NAME As String = String.Empty
    2.         Dim TempArray() As String
    3.         Dim i As Integer = 1
    4.  
    5.         If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then ' If file exists, then go on
    6.             FILE_NAME = OpenFileDialog1.FileName
    7.         End If
    8.  
    9.         Dim tempLine() As String = IO.File.ReadAllLines(FILE_NAME)
    10.         Dim NPuser(tempLine.Length - 1) As String
    11.         Dim NPpw(tempLine.Length - 1) As String
    12.  
    13.         For i = 1 To tempLine.GetUpperBound(0)
    14.             TempArray = tempLine(i).Trim.Split("/"c)
    15.             NPuser(i) = TempArray(0)
    16.             NPpw(i) = TempArray(1)
    17.             TempArray = Nothing
    18.         Next i
    19.  
    20.         MsgBox(NPuser(2) & " " & NPpw(2))
    21.  
    22.  
    23.     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
  •  



Click Here to Expand Forum to Full Width