none
想请教有关open file dialog 的代码 RRS feed

  • 问题

  • 当user open file dialog 时有会出现object reference not set to an instance of an object in textbox. 的error message。

    以下是我的代码。请指点

    Private Function OpenFile() As String

            Dim OFD As New OpenFileDialog
            With OFD
                .AddExtension = True
                .CheckFileExists = True
                .Filter = "Excel  files Excel files (*.xls)|*.xls"
                .Multiselect = False
                .Title = "Select an workbook to open"
            End With

            If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
                txtLocation.Text = OFD.FileName.ToString
                txtLocation1.Text = OFD.FileName.ToString
                Return OFD.FileName
            Else
                Return Nothing
            End If
        End Function

    2020年6月12日 2:23

全部回复

  • Hi christing,

    根据你的代码,我经过几次测试以后没有出现异常。

    为了更好的分析你的问题,请提供你调用 OpenFile() 时的相关的代码以及关于哪一行代码出现了异常的更多信息。

    期待你的更新。

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2020年6月12日 8:47
    版主