gpt4 book ai didi

vb.net - 在VB中处理OpenFileDialog时出错

转载 作者:行者123 更新时间:2023-12-03 08:56:33 28 4
gpt4 key购买 nike

我是VB的新手,所以我很欣赏这可能是一个愚蠢的问题。

我正在使用以下代码从本地文件系统中选择CSV文件。

    Dim openFileDialog1 As New OpenFileDialog

openFileDialog1.InitialDirectory = "c:\uploads"
openFileDialog1.Filter = "CSV files (*.csv)|*.csv"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True


If openFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

End If


'--TextField Parser is used to read the files
Dim parser As New FileIO.TextFieldParser(openFileDialog1.FileName)

如果未选择文件,如何正常显示此错误。

因此,实质上显示一条消息,指出“未选择文件”

先感谢您。

最佳答案

 Dim openFileDialog1 As New OpenFileDialog
Dim strFileName As String
openFileDialog1.InitialDirectory = "c:\uploads"
openFileDialog1.Filter = "CSV files (*.csv)|*.csv"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True

If openFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strFiilename = openFileDialog1.FileName
If strFileName <> "" Then
'file is selected
Dim parser As New FileIO.TextFieldParser(strFiilename)
Else
MsgBox("No File Selected")
End If
End If

我认为无需检查此 strFileName,因为在您的问题中您已放置
Dim parser As New FileIO.TextFieldParser(openFileDialog1.FileName)


If openFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
endif

这将导致您的错误

关于vb.net - 在VB中处理OpenFileDialog时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23337517/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com