【发布时间】:2015-08-23 03:26:48
【问题描述】:
我对 Visual Basic 还很陌生,所以这可能很明显,但我认为没有理由抛出和未强制转换的异常错误。问题代码如下:
Public Sub textBoxFilePath_TextChanged(sender As Object, e As EventArgs) Handles textboxFilePath.TextChanged
If textboxFilePath.Text.Trim.Length > 0 Then
If My.Computer.FileSystem.FileExists(textboxFilePath.Text) Then
Dim checkType As String
checkType = System.IO.Path.GetExtension(textboxFilePath.Text)
If checkType = ".xlsx" Or ".xls" Or ".xlsm" Then
requiredPath = True
Else
requiredPath = False
End If
End If
End If
我得到的错误是
Microsoft.VisualBasic.dll 中出现“System.InvalidCastException”类型的未处理异常
附加信息:从字符串“.xls”到类型“布尔”的转换无效。
有什么想法吗?
【问题讨论】:
标签: vb.net visual-studio