DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Raise Class Module Error from Form

  1. #1
    Jeremiah Guest

    Raise Class Module Error from Form


    Does anybody know if it is possible to raise an error in a class module method
    from within a form? E.g. A cancel button on a form that will make a method
    in a class module exit prematurely. Thanks in advance.

  2. #2
    Kenny Acock Guest

    Re: Raise Class Module Error from Form


    Jeremiah,

    >Does anybody know if it is possible to raise an error in a class module

    method
    >from within a form? E.g. A cancel button on a form that will make a method
    >in a class module exit prematurely. Thanks in advance.


    You could do this by creating a module-level variable to test for in your
    method:

    Private mbCancel As Boolean

    Public Sub Cancel()
    mbCancel = True
    End Property

    Public Sub MyMethod()
    Do While (Condition = True) And (mbCancel = False)
    'Do Something
    Loop
    End Sub


    --Kenny

  3. #3
    Larry Rebich Guest

    Re: Raise Class Module Error from Form

    Kenny,

    What if the process should be interrupted? The only example that I can think
    of would be to interrupt a DAO query. Your solution, a good one, assumes
    that some looping is taking place.

    I'd think firing an Event in the class module would be better - if it can be
    done?? Does anyone know how to do it?

    Cheers,
    Larry Rebich

    More tips link to:
    http://www.buygold.net/tips.html

    Please:
    No personal e-mail questions :-)


    "Kenny Acock" <kennya@teacherspal.com> wrote in message
    news:3a9bb8ec$1@news.devx.com...
    >
    > Jeremiah,
    >
    > >Does anybody know if it is possible to raise an error in a class module

    > method
    > >from within a form? E.g. A cancel button on a form that will make a

    method
    > >in a class module exit prematurely. Thanks in advance.

    >
    > You could do this by creating a module-level variable to test for in your
    > method:
    >
    > Private mbCancel As Boolean
    >
    > Public Sub Cancel()
    > mbCancel = True
    > End Property
    >
    > Public Sub MyMethod()
    > Do While (Condition = True) And (mbCancel = False)
    > 'Do Something
    > Loop
    > End Sub
    >
    >
    > --Kenny




  4. #4
    Kenny Acock Guest

    Re: Raise Class Module Error from Form


    Jeremiah

    >Does anybody know if it is possible to raise an error in a class module

    method
    >from within a form? E.g. A cancel button on a form that will make a method
    >in a class module exit prematurely. Thanks in advance.


    I thought of a second solution. Create an event. In the event have an argument
    (ByRef) that can be set to True for cancel:

    Public Event CancelMyMethod(ByRef bCancel As Boolean)

    Public Sub MyMethod()
    Dim bCancel As Boolean

    Do While (Condition = True) And (bCancel = False)
    'Do Something
    RaiseEvent CancelMyMethod(bCancel)
    Loop
    End Sub


    --Kenny

  5. #5
    Kenny Acock Guest

    Re: Raise Class Module Error from Form


    Larry,

    >I'd think firing an Event in the class module would be better - if it can

    be
    >done?? Does anyone know how to do it?


    I just finished a second reply with that suggestion just before reading this.
    (Yes, I assumed it was a loop because I could not think of any other
    scenario, other than external processes that are beyond the developer's control.)

    --Kenny

  6. #6
    Prashant Patel Guest

    Re: Raise Class Module Error from Form



    Define a Public Method in your class module. As part of this method Raise
    an Event which you want to handle.

    Call this method from your form. This will consequently fire the event.

    Prashant Patel


    "Kenny Acock" <kennya@teacherspal.com> wrote:
    >
    >Larry,
    >
    >>I'd think firing an Event in the class module would be better - if it can

    >be
    >>done?? Does anyone know how to do it?

    >
    >I just finished a second reply with that suggestion just before reading

    this.
    > (Yes, I assumed it was a loop because I could not think of any other
    >scenario, other than external processes that are beyond the developer's

    control.)
    >
    >--Kenny



  7. #7
    Michael Culley Guest

    Re: Raise Class Module Error from Form

    Kenny,

    You will need a doevents in there somewhere so that the cancel button can be
    pushed

    --
    Michael Culley
    www.vbdotcom.com
    "Kenny Acock" <kennya@teacherspal.com> wrote in message
    news:3a9bbec0@news.devx.com...
    >
    > Jeremiah
    >
    > >Does anybody know if it is possible to raise an error in a class module

    > method
    > >from within a form? E.g. A cancel button on a form that will make a

    method
    > >in a class module exit prematurely. Thanks in advance.

    >
    > I thought of a second solution. Create an event. In the event have an

    argument
    > (ByRef) that can be set to True for cancel:
    >
    > Public Event CancelMyMethod(ByRef bCancel As Boolean)
    >
    > Public Sub MyMethod()
    > Dim bCancel As Boolean
    >
    > Do While (Condition = True) And (bCancel = False)
    > 'Do Something
    > RaiseEvent CancelMyMethod(bCancel)
    > Loop
    > End Sub
    >
    >
    > --Kenny




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center