即使代码有效,也会出现InvalidCastException

时间:2015-03-03 21:28:30

标签: vb.net

下午好,

下面的代码是使用注册表项中的文件路径写入CSV文件。

Private Sub btnUPrint_Click(sender As Object, e As EventArgs) Handles btnUPrint.Click

    'ctrlPrintDoc.Print()

    Dim HistCSV As String

    HistCSV = My.Computer.Registry.GetValue(gRegKeyName, "History File Location", "")

    Dim out As System.IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(HistCSV, True)
    out.WriteLine(txtUChkNum.Text & "," & DateTimePicker1.Text & "," & txtUAmt.Text & "," & txtUPayTo.Text & "," & txtURef.Text)
    out.Close()

End Sub

即使代码确实有效(文件已创建并写入),我也会收到错误消息 “ChqPrint.exe中出现'System.InvalidCastException'类型的第一次机会异常

有人能让我知道如何解决这个问题吗?我正在使用vb.net而且还是初学者。

谢谢, 甲

0 个答案:

没有答案