OK. I'm not 100% sure where you may be having the syntax issue, so I will attempt to show several example pieces of code in an attempt to help.
Within the 'main' part of your form class area, where all the visible stuff is described, there should be something similar looking to this: (my example is using the AddHandler system, rather than the WithEvents system) (Link1)
Dim oCancelButton As New Button
With oCancelButton
.Text = "CANCEL"
.Top = oStartButton.Top
.Left = oStartButton.Right + 10
.Height = 25
.Width = 75
.Enabled = True
.Name = "CancelButton"
End With
oForm.CancelButton = oCancelButton
oForm.Controls.Add(oCancelButton)
AddHandler oCancelButton.Click, AddressOf oCancelButton_Click
But, of course you said your button is going to be labeled as an 'exit' button, and may be a different size & location.
Then outside of that 'main' area of your form class, but still within that class, you should have a Sub routine to handle the button click event. That might look something like this:
Private Sub oCancelButton_Click(ByVal oSender As System.Object, ByVal oEventArgs As System.EventArgs)
Me.Close
Dim oDoc As Inventor.Document = oInvApp.ActiveDocument
RuniLogicExternalRule("ExternalRuleName", oDoc)
End Sub
That method name would need to match your other custom Sub routine for running the rule...I just made that one up and reversed the order of the input variables from the documented one.
Then the custom Sub for running the external rule might look something like this:
Private Sub RuniLogicExternalRule(oRuleName As String, oDocForRuleToTarget As Inventor.Document)
Dim iLogicClassIDString As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
Dim iLogicAddIn As Inventor.ApplicationAddIn = Nothing
Try
iLogicAddIn = oInvApp.ApplicationAddIns.ItemById(iLogicClassIDString)
Catch
Exit Sub
End Try
If Not iLogicAddIn.Activated Then iLogicAddIn.Activate
Dim oAuto As Object = iLogicAddIn.Automation
Try
i = oAuto.RunExternalRule(oDocForRuleToTarget, oRuleName)
Catch
End Try
End Sub
Since you are going to be running an external rule from the button, then there are only two methods available for that. The RunExternalRule method, and the RunExternalRuleWithArguments method. Within your code for the sub to run the rule, you will most likely not have any 'Intellisense' type help after the iLogic AddIn's Automation object, because it will just be recognized as a generic Object. But you should be able to just put one of those method codes after the 'dot', (right after that automation object variable) to be able to use them, as seen in the above example.
Again, these are just quickie rough example bits.
Wesley Crihfield

(Not an Autodesk Employee)