Reputation: 728
I have a section of code that is appearing to 'jump'
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
The code runs correctly to display msgbox("start")
It then offers the browse dialog (on the next line of code) but then appears to execute the line LoadDatasets()
(just above End Sub
)
This subroutine (LoadDatasets()
) has a try, catch statement with a messagebox on the catch, this message box is appearing next.
After you click OK (on the msgbox in LoadDatasets()) you get the MsgBox(My.Settings.DefaultLocation)
on line 10 appear.
The FileBrowse()
code is as follows:
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
Any ideas?
Upvotes: 1
Views: 257
Reputation: 101042
Maybe the code "appears to execute LoadDatasets()
" because FileBrowse
actually calls 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
Upvotes: 2