当前位置: 代码迷 >> VB Dotnet >> 编译出错解决思路
  详细解决方案

编译出错解决思路

热度:95   发布时间:2016-04-25 02:12:44.0
编译出错
读取文本到字符串数组,然后判断读出的每一行是不是为空,如果为空赋默认值
不知道出错在哪里,初用VB.net,高手们请指点一下

------解决方案--------------------
在读取之前检查数组是否有值和数量
------解决方案--------------------
示例:

Imports System
Imports System.IO

Public Class Test
    Public Shared Sub Main()
        Dim path As String = "c:\temp\MyTest.txt"
        Dim sw As StreamWriter

        ' This text is added only once to the file.
        If File.Exists(path) = False Then

            ' Create a file to write to.
            Dim createText() As String = {"Hello", "And", "Welcome"}
            File.WriteAllLines(path, createText)
        End If

        ' This text is always added, making the file longer over time
        ' if it is not deleted.
        Dim appendText As String = "This is extra text" + Environment.NewLine
        File.AppendAllText(path, appendText)

        ' Open the file to read from.
        Dim readText() As String = File.ReadAllLines(path)
        Dim s As String
        For Each s In readText
            Console.WriteLine(s)
        Next
    End Sub
End Class
  相关解决方案