2

I am trying to RaiseEvent from a button, this button is located in a Form. Then the idea is to raise the final even to the usercontrol.

I have tried the next code:

Form1

Dim Sec As Integer
Public Event TestEvent()

Private Sub Command1_Click()
RaiseEvent TestEvent
End Sub

usercontrol

Option Explicit
Dim WithEvents f1 As Form1
Dim f2 As Form2

Private Sub f1_TestEvent()
f2.Show
End Sub

Private Sub UserControl_Initialize()
Set f1 = New Form1
f1.Show
Set f2 = New Form2
End Sub

Form2

No code, it is just to verify if the event is raised.

And unfortunately it is not working as I expect.

I hope my question is clear. Thanks

  • 1
    What does "not working" mean? – StayOnTarget Aug 22 '22 at 11:42
  • Hello @StayOnTarget thanks for the answer, meaning that its not raising the event, I trace the event, and in the FORM is raising the event, but when I try to trace it in the USERCONTROL never raise the event, but I have tested this exact code with 2 FORMS and it is triggering the event of the second FORM, I hope it is clear, and once more thanks – DiegoSan1986 Aug 22 '22 at 11:57
  • 1
    Is this all of your code? – Brian M Stafford Aug 22 '22 at 13:05
  • Hello @StayOnTarget thanks a lot for your answer, for the test, yes its the only code I have in it, but the final build has code related to image change, text change and property get and let(all of this is located in the USERCONTROL), and also I have a Module with global variables, I am not sure if I can upload my code, but if I can, for sure I can upload it, and once more thanks a lot for your questions/support. – DiegoSan1986 Aug 22 '22 at 13:42
  • 1
    You don't need to post all of your code, but please provide a minimum complete example (see [mcve](https://stackoverflow.com/help/minimal-reproducible-example)). What is posted currently isn't sufficient to diagnose the described issue - indeed, while it instantiates it, the Form1 instance that resides in the usercontrol isn't displayed. – MarkL Aug 22 '22 at 14:55
  • Hello all. I just notices that, if I test the project I am developing directly with VB6, it is doing correctly the change/event in the usercontrol. The issue is, when I load the OCX to the final product (HMI-WinCC) and its not triggering the event/change, is there any other way to trigger an event?. Thanks – DiegoSan1986 Aug 22 '22 at 18:12
  • 1
    The code as posted above does not work which goes back to the comment about posting a complete example. However, if code works in the VB6 IDE then it should work in the compiled code, too. I've never seen an event not work in compiled code. – Brian M Stafford Aug 22 '22 at 18:22
  • Hello. I have edited the code. As I mentioned, it is working running directly with VB6, but when I try to register the OCX in the third party software, it is now raising the event, is there any other way to raise the event?, Thanks – DiegoSan1986 Aug 22 '22 at 18:54
  • Hello all. I see what the problem is. the third party software cant handle an event when the form is shown, in order to make it work, is to unload the form, and the it will execute the raise of event. I am not sure if its a limitation, or its my code, since it is working fine running directly with the VB6 IDE. Do you have any other idea or advise? Thanks – DiegoSan1986 Aug 22 '22 at 19:42
  • You should edit the question to provide new information ... you don't just have to leave comments. – StayOnTarget Aug 23 '22 at 11:49
  • And as others have said, provide more details of the real code you are using. – StayOnTarget Aug 23 '22 at 11:49

0 Answers0