-
Feb 15th, 2019, 02:56 PM
#1
Thread Starter
Member
[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.
-
Feb 15th, 2019, 03:19 PM
#2
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
-
Feb 15th, 2019, 03:43 PM
#3
Thread Starter
Member
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. :/
-
Feb 15th, 2019, 03:52 PM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|