Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Events in Interfaces (XP SP3)

    Hello everybody,

    just a general question: is it possible to fire events within custom user interfaces? I have programmed a class module that fires events for a worksheet. Now I have to write a second class modules, that is pretty much like the first one despite the fact that now I have to deal with some changed pre-conditions. I would like to use an interface. It works very well, but unfortunately, I cannot make it respond to events.
    Any ideas? Or is it just a too strange idea of mine?

    Any help will be appreciated!

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Events in Interfaces (XP SP3)

    What exactly do you mean by an interface?
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Events in Interfaces (XP SP3)

    Could you provide a bit more detail? It's not clear to me what you mean.

  4. #4
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Events in Interfaces (XP SP3)

    Sorry for my rough description. I will prepare an example file and be back soon.
    Thank you so far for replying.

  5. #5
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Events in Interfaces (XP SP3)

    OK, I'm back again. Sorry, it took some time to prepare an example sheet, but here it is, and I hope that I can describe my idea more precisely. When you open the example sheet, you will find three buttons (Start I | Start II | Stop). Pressing Start I or Start II calls the routine MTest.StartEvents with one parameter, which is the pressed button as an CommandButton. Depending on the given parameter, the object variable mclsTest is instanciated as CTest1 or CTest2. The variable itself is of type ITest, which is the mentioned interface. This interface is implemented by both CTest1 and CTest2. Both CTest-objects include a Sheet-variable (mwksMySheet) which is declared with WithEvents parameter set. What I would like to do, is to do this declaration within the interface. Also, I would like to reduce the events which are fired to the Workbook_SelectionChange event (for example). Doing this in an interface would ensure, that I could only use this certain event within the classes CTest1 and CTest2.
    This example is very simple, and what you find in here does not really make sense. The real case is much more complex, and the ability of realizing the described concept could lead to some benefit when writing classes using interfaces for third parties.
    Every comment on this will be highly appreciated, even if it is "forget about this"
    Many thanks for your support in advance!

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Events in Interfaces (XP SP3)

    This is beyond me, I hope that someone else can comment on it.

  7. #7
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Events in Interfaces (XP SP3)

    This makes me fear that it won't work... Thank you very much for your reply. Maybe somebody else has an idea about this or knows a good resource in the internet about the use of interfaces? I am highly interested in learning more about it.

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Events in Interfaces (XP SP3)

    Is the attached the sort of thing you had in mind?
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Events in Interfaces (XP SP3)

    Hello Rory,

    thanks a lot for your work. Yes, you perfectly met what I had in mind. It seems, that interfaces are more flexible than I thought. I did not realize that I additionally can declare a variable as Interface when I already implement this interface in my class.
    So this was very helpful for me. Are there any other interesting concepts about interfaces?

  10. #10
    2 Star Lounger
    Join Date
    Mar 2002
    Location
    Germany, Germany
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Events in Interfaces (XP SP3)

    Thanks again. I will start playing around with this concept and figure out what I can do with it in detail. Thanks for the article, I will read it but I guess it will need some time to make my way through. Of course, I know the book "Professional Excel Development". It is the best resource for programming I know. <img src=/S/cool.gif border=0 alt=cool width=15 height=15>

  11. #11
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Events in Interfaces (XP SP3)

    Because your interface is also a class, you can use it as you would any other class, hence you can use the withevents variable (and , as far as I know, that is the only way to do what you want).
    There's an interesting Technet article on classes and interfaces here and if you haven't already got a copy of Professional Excel Development by Bovey, Bullen and Green, I would strongly recommend it! <img src=/S/yep.gif border=0 alt=yep width=15 height=15>
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •