kobiyashi Level: Trainee
 Registered: 15-11-2007 Posts: 1
|
Object reference not set to an instance of an object.
This is probably some extremely silly error on my part, as they usually are. Also this problem it probably way below the knowledge level of you guys but I need to get this done. It's a simple app that's supposed to find how many vowels there are in words from a text file. I get the topic error at the line
letter = word.Substring(x, 1)
When I comment out stars = "", stars has a value of quite a few *'s which makes me think this error happens rather late in the process. Can you guys help me out?
Public Class Form1
Private Sub thelastbutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles thelastbutton.Click
Dim file As IO.StreamReader = IO.File.OpenText("c:\words2.txt")
Dim word As String
Dim letter As String = ""
Dim x As Integer
Dim stars As String = ""
Do
x = 1
stars = ""
word = file.ReadLine
Do
letter = word.Substring(x, 1)
If letter.ToLower = "a" Or letter.ToLower = "e" Or letter.ToLower = "i" Or letter.ToLower = "o" Or letter.ToLower = "u" Then
stars = stars + "*"
End If
x = x + 1
Loop Until x = word.Length
lastlist.Items.Add(stars)
Loop Until word = ""
file.Close()
End Sub
End Class
|