|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ActiveX Control Crashes - VB6the application that uses the ActiveX control. The application that uses the ActiveX control uses END to stop the application if a certain condition occurs and it crashes the application. Why does this happen and is there any way to fix it? Code in the ActiveX control Sub Process1 If condition true then RasieEvent Event1 end if End sub Code in main application that uses ActiveX Control Sub ActiveX_Event1 'this is where it crashes end end sub I don't quite understand why it does that. Is there any way to prevent it? Thanks for the help. Let me be the first - NEVER use End, it is a throwback and it stops the
program, dead, without really clearing up properly. Get rid of the End, close the application properly and then see if the problem persists. Dave O. Show quoteHide quote "Jonathan" <Jonat***@discussions.microsoft.com> wrote in message news:97FECABD-134E-468A-A7B0-37B3261F4101@microsoft.com... >I have an ActiveX control I custom made. It has an event that is handled by > the application that uses the ActiveX control. The application that uses > the > ActiveX control uses END to stop the application if a certain condition > occurs and it crashes the application. Why does this happen and is there > any > way to fix it? > > > Code in the ActiveX control > > Sub Process1 > > > If condition true then > RasieEvent Event1 > end if > > End sub > > > > > Code in main application that uses ActiveX Control > > Sub ActiveX_Event1 > > 'this is where it crashes > end > > end sub > > > I don't quite understand why it does that. Is there any way to prevent it? > Thanks for the help. Dave,
I switched to unload me. Is that any better than end? Here is my full code.It reproduces the error in the main application I have thats mroe complex. '---------------------- OCX ---------------------- Event OnRecieve() Public Function OpenPort(Num As Integer) As Boolean On Error GoTo EventHandler OpenPort = False With Com .CommPort = Num .PortOpen = True End With Exit Function OpenPort = True EventHandler: End Function Private Sub Com_OnComm() If Com.CommEvent = 2 Then 'Trigger an even when data is recieved RaiseEvent OnRecieve End If End Sub Private Sub UserControl_Terminate() 'close the port Com.PortOpen = False End Sub '--------------------- App --------------------------- Private Sub Form_Load() TestControl1.OpenPort (1) End Sub Private Sub TestControl1_onRecieve() Unload Me 'crashes after the end sub End Sub Interestingly enough, the program does not crash when the close button is pressed. The main app just have a standard form on it. Show quoteHide quote "Dave O." wrote: > Let me be the first - NEVER use End, it is a throwback and it stops the > program, dead, without really clearing up properly. > Get rid of the End, close the application properly and then see if the > problem persists. > > Dave O. > > "Jonathan" <Jonat***@discussions.microsoft.com> wrote in message > news:97FECABD-134E-468A-A7B0-37B3261F4101@microsoft.com... > >I have an ActiveX control I custom made. It has an event that is handled by > > the application that uses the ActiveX control. The application that uses > > the > > ActiveX control uses END to stop the application if a certain condition > > occurs and it crashes the application. Why does this happen and is there > > any > > way to fix it? > > > > > > Code in the ActiveX control > > > > Sub Process1 > > > > > > If condition true then > > RasieEvent Event1 > > end if > > > > End sub > > > > > > > > > > Code in main application that uses ActiveX Control > > > > Sub ActiveX_Event1 > > > > 'this is where it crashes > > end > > > > end sub > > > > > > I don't quite understand why it does that. Is there any way to prevent it? > > Thanks for the help. > > > "Jonathan" <Jonat***@discussions.microsoft.com> wrote "I'm leaving now, would you like me to close the door on> I switched to unload me. Is that any better than end? my way out... ...or destroy the house as I go?" The difference between the two is about that drastic. At first glance, it would seem you've got yourself into a situation that has no easy solution. You want to unload the form that contains a control, from within the control's event handler. But in some (not all) circumstances, VB is expecting to return to code located in the control, so how can it be unloaded? When VB gets into a situation like that, it throws an error, (Error 365) but that error isn't trappable, so you can't test for it.... To see the different conditions VB handles like that, paste this into a new form, run it, and press the Help button on the Error dialog: Private Sub Form_Paint() Unload Me End Sub Their solution is to remove the Unload command from the offending routine. That is about all you can do in your own situation.... LFS Larry Serflaten wrote:
> "Jonathan" <Jonat***@discussions.microsoft.com> wrote Best language-car analogy ever: Using End to stop your application is like using a > >> I switched to unload me. Is that any better than end? > > "I'm leaving now, would you like me to close the door on > my way out... ...or destroy the house as I go?" > > The difference between the two is about that drastic. telephone pole to stop your car. Highly effective, both! Hi Jonathan,
Try closing the com port before closing the form. Show quoteHide quote "Jonathan" <Jonat***@discussions.microsoft.com> wrote in message news:6F184338-CFB1-4123-976F-566A95BDDACB@microsoft.com... > Dave, > > I switched to unload me. Is that any better than end? > > Here is my full code.It reproduces the error in the main application I > have > thats mroe complex. > > > '---------------------- OCX ---------------------- > Event OnRecieve() > > Public Function OpenPort(Num As Integer) As Boolean > > On Error GoTo EventHandler > > OpenPort = False > > With Com > .CommPort = Num > .PortOpen = True > End With > > Exit Function > > OpenPort = True > > EventHandler: > > End Function > > Private Sub Com_OnComm() > > If Com.CommEvent = 2 Then > 'Trigger an even when data is recieved > RaiseEvent OnRecieve > End If > > End Sub > > Private Sub UserControl_Terminate() > 'close the port > Com.PortOpen = False > End Sub > > > > > '--------------------- App --------------------------- > Private Sub Form_Load() > TestControl1.OpenPort (1) > > End Sub > > Private Sub TestControl1_onRecieve() > > Unload Me > 'crashes after the end sub > End Sub > > > Interestingly enough, the program does not crash when the close button is > pressed. The main app just have a standard form on it. > > > > > "Dave O." wrote: > >> Let me be the first - NEVER use End, it is a throwback and it stops the >> program, dead, without really clearing up properly. >> Get rid of the End, close the application properly and then see if the >> problem persists. >> >> Dave O. >> >> "Jonathan" <Jonat***@discussions.microsoft.com> wrote in message >> news:97FECABD-134E-468A-A7B0-37B3261F4101@microsoft.com... >> >I have an ActiveX control I custom made. It has an event that is handled >> >by >> > the application that uses the ActiveX control. The application that >> > uses >> > the >> > ActiveX control uses END to stop the application if a certain condition >> > occurs and it crashes the application. Why does this happen and is >> > there >> > any >> > way to fix it? >> > >> > >> > Code in the ActiveX control >> > >> > Sub Process1 >> > >> > >> > If condition true then >> > RasieEvent Event1 >> > end if >> > >> > End sub >> > >> > >> > >> > >> > Code in main application that uses ActiveX Control >> > >> > Sub ActiveX_Event1 >> > >> > 'this is where it crashes >> > end >> > >> > end sub >> > >> > >> > I don't quite understand why it does that. Is there any way to prevent >> > it? >> > Thanks for the help. >> >> >>
My concept for a very basic stripboard layouter in VB6
Put Date/Time on Right Side of Form.Caption With .... End With - Speed Public Thank You To Microsoft Days and Years - Data Comparing Does anybody know how to translate this C# code to VB6? Copy protection and license management programs Need a Friend, Maybe Which is the Best Twain ActiveX? Error 6 Overflow when multiply |
|||||||||||||||||||||||