代码似乎在vb.net中跳转

时间:2013-09-11 08:35:32

标签: vb.net winforms

我有一段看似“跳”的代码

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上有一个消息框,这个消息框出现在下一个。

单击“确定”后(在LoadDatasets()中的msgbox上),您将看到第10行的MsgBox(My.Settings.DefaultLocation)

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

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

也许代码“似乎执行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
相关问题