Results 1 to 6 of 6

Thread: [RESOLVED] Is therea way to handle events in a sorted list?

  1. #1

    Thread Starter
    Addicted Member ThatSamiam's Avatar
    Join Date
    Apr 2007
    Posts
    128

    Resolved [RESOLVED] Is therea way to handle events in a sorted list?

    Hi,

    Suppose I have this class which can raise an event:

    Code:
    Public Class eRaiser
      Event sendInfo(ByVal info As String)
    
      Public Sub InfoEventRaiser(ByVal info As String)
        RaiseEvent sendInfo(info)
      End Sub
    End Class
    If I have one of these, I can make an event handler:

    Code:
      Public WithEvents er As New eRaiser
      Sub erHandler(ByVal info As String) Handles er.sendInfo
    
      End Sub
    Now, let's suppose I need to have a sorted list of these:

    Code:
     Public WithEvents ers As New SortedList(Of Integer, eRaiser)
    Is there a way to reference the event individually or collectively?

    Code:
    Sub ersHandler(ByVal info As String) Handles ers???
    Thanks

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Is therea way to handle events in a sorted list?

    You would need to use AddHandler to wire up the event to the eventhandler at run time when you create the eRaiser object and add it to your list.


    Code:
    Sub ersHandler(ByVal info As String) 'No handles
    
    ... do your thing ...
    Code:
    Sub AddNeweRaiser()
    
      dim er as new eRaiser
      AddHandler er.sendInfo, AddressOf ersHAndler
      ers.Add(ers.count +1, er)
    
    end sub
    Something along those lines... you create the individual object, wire it up to your handler, then add it to your list.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Is therea way to handle events in a sorted list?

    I would make the SortedList part of the class and pass into an event so it could be consumed when the event is called.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  4. #4

    Thread Starter
    Addicted Member ThatSamiam's Avatar
    Join Date
    Apr 2007
    Posts
    128

    Re: Is therea way to handle events in a sorted list?

    Wow. Two very fast replies, thanks.

    Could you also suggest a way that the handler would know which er (key) raised the event?

    Thanks

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Is therea way to handle events in a sorted list?

    Well if you follow the standard convention of sender, eventargs... then it would be easy...

    Code:
    Public Class eRaiser
      public class eRaiserEventArg
            inherits SystemEventArgs 'I think that's right.
    
        public property Info as string
    
      end class
    
      Event sendInfo(ByVal sender as object, ByVal e As eRaiserEventArg) '
    
      Public Sub InfoEventRaiser(ByVal info As String)
        Dim evtArg as new eRaiserEventArg with {.Info = info}
        RaiseEvent sendInfo(me, evtArg)
      End Sub
    Then your handler stub looks like this:
    Code:
    Sub ersHandler(byval sender as object, byval e as eRaiserEventArg)
    'Now Sender is the object that riased the event
    Should all look somewhat familiar as it's the same pattern nearly every control and object follows.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Addicted Member ThatSamiam's Avatar
    Join Date
    Apr 2007
    Posts
    128

    Re: Is therea way to handle events in a sorted list?

    Thanks for the help - and for setting me straight on the wisdom of using standard arguments sender and e.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width