循环后VB程序停止

时间:2011-06-12 22:58:09

标签: vb.net loops

我正在使用VB 2101 express,我试着修改这个程序,但它不会超过我的循环结束,有人知道为什么吗?

If (Not System.IO.Directory.Exists(root + "\setting")) Then
    System.IO.Directory.CreateDirectory(root + "\setting")
End If

'loads world settings
If File.Exists(root + "\setting\world.txt") Then
    Dim ioFile As New StreamReader(root + "\setting\world.txt")
    Dim ioLine As String ' Going to hold one line at a time
    Dim ioLines As String ' Going to hold whole file

    ioLine = ioFile.ReadLine
    ioLines = ioLine

    Do
         ioLine = ioFile.ReadLine
         ioLines = ioLines & vbCrLf & ioLine
         cmbworld.Items.Add(ioLine)
    Loop Until ioLine = "" '***<--- IT STOPS HERE!***

Else
    System.IO.File.Create(root + "\setting\world.txt")
End If

2 个答案:

答案 0 :(得分:2)

这不是更简单吗?

For Each line As String In File.ReadLines("root + "\setting\world.txt"")
    If line.Length <> 0 Then
        cmbworld.Items.Add(line)
    End If
Next line

MSDN: File.ReadLines Method (String)

答案 1 :(得分:0)

尝试将最后一行设为Loop Until ioLine is nothing