1

我有一段代码似乎“跳转”

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    SU_DefaultLoc.Text = My.Settings.DefaultLocation
    If My.Settings.DefaultLocation = "" Or File.Exists(My.Settings.DefaultLocation) = False Then
        MsgBox("start")
        My.Settings.DefaultLocation = FileBrowse(My.Settings.DefaultLocation)
        MsgBox(My.Settings.DefaultLocation)
        My.Settings.Save()
    End If
    If My.Settings.SaveLocation = "" Then
        My.Settings.SaveLocation = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        My.Settings.Save()
    End If
    SU_DefaultLoc.Text = My.Settings.DefaultLocation
    Me.Text = "Delivery Scheduling - Version " & Me.ProductVersion
    My.Settings.UpdateLoad = False
    My.Settings.Save()
    LoadDatasets()
End Sub

代码运行正确显示msgbox("start")

然后它提供浏览对话框(在下一行代码上),但随后似乎执行了该行LoadDatasets()(就在上面End Sub

这个子例程 ( LoadDatasets()) 有一个 try, catch 语句,在 catch 上带有一个消息框,接下来会出现这个消息框。

单击 OK(在 LoadDatasets() 中的 msgbox 上)后,您会看到第MsgBox(My.Settings.DefaultLocation)10 行。

FileBrowse()代码如下:

    Function FileBrowse(Optional Location As String = "", _
                Optional Title As String = "Browse to the folder that stores the import files and click 'Open'") As String
    If Location = "" Then Location = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Show Browse Info
    With FBD
        .InitialDirectory = Replace(Location, Split(Location, "\").ElementAt(UBound(Split(Location, "\"))), "")
        .Title = Title
    End With
    If FBD.ShowDialog() = Windows.Forms.DialogResult.OK Then
        'clear old settings
        My.Settings.VanLoadDetails.Clear()
        My.Settings.OrderData.Clear()
        My.Settings.UpdateLoad = False
        FileBrowse = FBD.FileName
        LoadDatasets()
    Else
        'Do Nothing
        FileBrowse = ""
         End If

End Function

有任何想法吗?

4

1 回答 1

2

也许代码“似乎执行LoadDatasets()”是因为FileBrowse实际调用LoadDatasets()

Function FileBrowse(Optional Location As String = "", _
                Optional Title As String = "Browse to the folder that stores the import files and click 'Open'") As String
    If Location = "" Then Location = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Show Browse Info
    With FBD
        .InitialDirectory = Replace(Location, Split(Location, "\").ElementAt(UBound(Split(Location, "\"))), "")
        .Title = Title
    End With
    If FBD.ShowDialog() = Windows.Forms.DialogResult.OK Then
        ...
        LoadDatasets() ' <--- here'
    Else
        ...

End Function
于 2013-09-11T10:04:26.127 回答