Public Class frmProgress Private Sub btnBrowseGPX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseGPX.Click Call Procedures.GetGPXPath() End Sub Private Sub btnBrowseGDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseGDB.Click Call Procedures.GetGDBPath() End Sub Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click ' Close the form, but continue with the code in Procedures. Me.Hide() bContinue = True End Sub Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click ' Exit the Do loop in Procedures using the continue boolean and close the form. bContinue = False Me.Close() End Sub Private Sub frmProgress_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If e.CloseReason = Windows.Forms.CloseReason.UserClosing Then bContinue = False e.Cancel = False End If End Sub End Class
Solved! Go to Solution.
Do ' Declare and initialize variables. Dim pUID As IUID Dim pLayer As ILayer Dim pEnumLayer As IEnumLayer Dim pMxDoc As IMxDocument Dim pMap As IMap pMxDoc = My.ArcMap.Document pMap = pMxDoc.FocusMap ' Set UID to retrieve IFeatureLayer which can be QI'd to ILayer. pUID = New UID pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}" ' Get list of all feature layers in the map. True means recursive so it will return all feature layers in the table of contents. ' Set iterator to the front of the list. pEnumLayer = pMap.Layers(pUID, True) pEnumLayer.Reset() ' Get first layer in list, and QI to ILayer (to make use of the .Name property). pLayer = pEnumLayer.Next ' Clear the combo boxes in case the user has already attempted to proceed without filling all parameters out. frmProgress.cbTWPLayer.Items.Clear() frmProgress.cbLSDLayer.Items.Clear() ' Iterate through layers to populate combo box list. Do Until pLayer Is Nothing frmProgress.cbLSDLayer.Items.Add(pLayer.Name) frmProgress.cbTWPLayer.Items.Add(pLayer.Name) pLayer = pEnumLayer.Next() Loop ' Display the form. frmProgress.ShowDialog() ' OK and Cancel buttons determine whether or not to proceed. If Not Procedures.bContinue Then Exit Sub Else ' Store information from combo boxes. sLSD = frmProgress.cbLSDLayer.Text sTWP = frmProgress.cbTWPLayer.Text If sGPXPathPublic = "" Or sGDBPathPublic = "" Or sLSD = "" Or sTWP = "" Then MsgBox("You must fill out all parameters.") Continue Do Else Call Procedures.Main(frmProgress) Exit Sub End If End If Loop
Thanks for the helpful reply.
That makes some sense to me. That behaviour wasn't intentional, but I don't see it as being bad (at least in this particular case)...is that bad practice that the variables are remaining as is?
I have an additional question as well. When the form closes (either cancel or 'X') it should be setting bContinue = False. Shouldn't this exiting of the main Subroutine call the garbage collection and dereference any variables? Mainly wondering if I should "fix" the fact that the variables aren't being dereferenced.
Fair answer, in this case I don't think it's a bad thing. In the bigger picture, because it wasn't intended, I'm not 100% happy with it, but that's ok for now. At least I've been given a good explanation.
As for the Do Loop, it's purpose is to prevent the form from closing when the user hits 'OK' without having filled out the required parameters.
Without it, they're warned that they didn't fill everything out, but because the OK button hides the form (with the expectation that it will proceed with the rest of the code), they have to re-run the Add-In. It's not required, but I like the idea that if they forget 1 thing, they don't have to go back and re-do everything.
Thus the reason as well to handle form closing event. If they hit cancel or 'X' I know they don't want to continue, but the code doesn't unless I tell it.