Results 1 to 4 of 4

Thread: [RESOLVED]Substring problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    31

    Resolved [RESOLVED]Substring problem

    Hey guys! Whats wrong with this code? I cant find out
    Code:
    Dim streamer As System.IO.StreamReader
    streamer = My.Computer.FileSystem.OpenTextFileReader("kerdes.txt")
    Dim temp As String = streamer.ReadLine()
    temp = temp.Replace(" ", "")
    valasz(i, j) = temp
    It gives me the "Additional information: Object reference not set to an instance of an object." at the line temp = temp.Replace...
    Last edited by Daveeed; Feb 15th, 2019 at 03:52 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,023

    Re: Substring problem

    Yeah, that seems a bit surprising. When the exception happens, highlight temp and press Ctrl+F9. If that shows Nothing, then temp is Nothing, which seems like the only candidate, in this case. You can't call a method of Nothing.

    Of course, that would just be the beginning of the puzzle, because you set temp to streamer.ReadLine() in the previous line, so that would have to be returning Nothing, which a StreamReader will do if the end of the file is reached. I would guess that you'd be surprised to find that the end of the file was reached the first time you tried to read a line. Could the file be empty?
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    31

    Re: Substring problem

    No, its not. I've tried this :
    Code:
    Dim temp As String = streamer.ReadLine()
                    MsgBox(temp)
                    temp = temp.Replace(" ", "")
    and it shows me the right string in the msgbox. So no, its not Nothing. :/

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    31

    Re: Substring problem

    I'm sorry, after 1 hour I found the mistake. I ran it step by step, and it ran out of bounds the for cycle. Thanks anyway!

Tags for this Thread

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