Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. MS at it again

MS at it again

Scheduled Pinned Locked Moved Visual Basic
questionhelptutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treddie
    wrote on last edited by
    #1

    Hi all. Sorry for the frustration here, but I always dread going to MS for any kind of help anymore, regarding what this-or-that does. For years now, they are extremely spotty in their ability to describe something simply and unambiguously. Below is a perfect example; a paragraph which talks in circles: "The WithEvents statement and the Handles clause provide a declarative way of specifying event handlers. An event raised by an object declared with the WithEvents keyword can be handled by any procedure with a Handles statement for that event, as shown in the following example:" Sounds like lawyer talk, so whenever I run into lawyer talk, I try to reword it into an explicit example. So here goes. "A button's mouse click event raised by a button, declared with the WithEvents keyword can be handled by any procedure with a Handles statement for the button mouse click event..." That's like saying "A box with a lid, has a lid on it." It seems to be saying that if I use the WithEvents keyword, I can attach, for example, the statement, "Handles Button3.Click" on to ANY procedure and the procedure will respond to the Button3.Click event. Well...Duh! I can do that withOUT the WithEvents keyword! So what is the difference? Or did they MEAN to say, "A user can declare a custom event with the WithEvents keyword. Then, any procedure can use that event just like any other event, by attaching it at the end of a procedure's declaration, with the "Handles" clause." If so, why use the keyword "WithEvents at all? Why not just,

    Public Event MyCustomEvent
    'Description of event goes here.
    End Event

    OR, are they trying to say this, 'Using the WithEvents keyword, a class is declared that can contain multiple events, any of which can be used at the end of a procedure's declaration with the "Handles" clause. For example,

    'Declare a new collection of events:
    Dim WithEvents MyEventsCollection As New EventsCollection1

    'Create the class, declared above:
    Class EventsCollection1
    Public Event My1stEvent()
    Public Event My2ndEvent()
    End Class

    'Then, any procedure can have a Handles clause at the end of it, which assigns any of the events in the collection,

    Private Sub ThisProcedure() Handles EventsCollection1.My1stEvent
    '...Do stuff.
    End Sub

    If THAT is what they mean, why put all of those events in a collection (a Class), instead of just calling them all out in

    L D 2 Replies Last reply
    0
    • T treddie

      Hi all. Sorry for the frustration here, but I always dread going to MS for any kind of help anymore, regarding what this-or-that does. For years now, they are extremely spotty in their ability to describe something simply and unambiguously. Below is a perfect example; a paragraph which talks in circles: "The WithEvents statement and the Handles clause provide a declarative way of specifying event handlers. An event raised by an object declared with the WithEvents keyword can be handled by any procedure with a Handles statement for that event, as shown in the following example:" Sounds like lawyer talk, so whenever I run into lawyer talk, I try to reword it into an explicit example. So here goes. "A button's mouse click event raised by a button, declared with the WithEvents keyword can be handled by any procedure with a Handles statement for the button mouse click event..." That's like saying "A box with a lid, has a lid on it." It seems to be saying that if I use the WithEvents keyword, I can attach, for example, the statement, "Handles Button3.Click" on to ANY procedure and the procedure will respond to the Button3.Click event. Well...Duh! I can do that withOUT the WithEvents keyword! So what is the difference? Or did they MEAN to say, "A user can declare a custom event with the WithEvents keyword. Then, any procedure can use that event just like any other event, by attaching it at the end of a procedure's declaration, with the "Handles" clause." If so, why use the keyword "WithEvents at all? Why not just,

      Public Event MyCustomEvent
      'Description of event goes here.
      End Event

      OR, are they trying to say this, 'Using the WithEvents keyword, a class is declared that can contain multiple events, any of which can be used at the end of a procedure's declaration with the "Handles" clause. For example,

      'Declare a new collection of events:
      Dim WithEvents MyEventsCollection As New EventsCollection1

      'Create the class, declared above:
      Class EventsCollection1
      Public Event My1stEvent()
      Public Event My2ndEvent()
      End Class

      'Then, any procedure can have a Handles clause at the end of it, which assigns any of the events in the collection,

      Private Sub ThisProcedure() Handles EventsCollection1.My1stEvent
      '...Do stuff.
      End Sub

      If THAT is what they mean, why put all of those events in a collection (a Class), instead of just calling them all out in

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      treddie wrote:

      If so, why use the keyword "WithEvents at all? Why not just,

      "VB6"

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      T 1 Reply Last reply
      0
      • T treddie

        Hi all. Sorry for the frustration here, but I always dread going to MS for any kind of help anymore, regarding what this-or-that does. For years now, they are extremely spotty in their ability to describe something simply and unambiguously. Below is a perfect example; a paragraph which talks in circles: "The WithEvents statement and the Handles clause provide a declarative way of specifying event handlers. An event raised by an object declared with the WithEvents keyword can be handled by any procedure with a Handles statement for that event, as shown in the following example:" Sounds like lawyer talk, so whenever I run into lawyer talk, I try to reword it into an explicit example. So here goes. "A button's mouse click event raised by a button, declared with the WithEvents keyword can be handled by any procedure with a Handles statement for the button mouse click event..." That's like saying "A box with a lid, has a lid on it." It seems to be saying that if I use the WithEvents keyword, I can attach, for example, the statement, "Handles Button3.Click" on to ANY procedure and the procedure will respond to the Button3.Click event. Well...Duh! I can do that withOUT the WithEvents keyword! So what is the difference? Or did they MEAN to say, "A user can declare a custom event with the WithEvents keyword. Then, any procedure can use that event just like any other event, by attaching it at the end of a procedure's declaration, with the "Handles" clause." If so, why use the keyword "WithEvents at all? Why not just,

        Public Event MyCustomEvent
        'Description of event goes here.
        End Event

        OR, are they trying to say this, 'Using the WithEvents keyword, a class is declared that can contain multiple events, any of which can be used at the end of a procedure's declaration with the "Handles" clause. For example,

        'Declare a new collection of events:
        Dim WithEvents MyEventsCollection As New EventsCollection1

        'Create the class, declared above:
        Class EventsCollection1
        Public Event My1stEvent()
        Public Event My2ndEvent()
        End Class

        'Then, any procedure can have a Handles clause at the end of it, which assigns any of the events in the collection,

        Private Sub ThisProcedure() Handles EventsCollection1.My1stEvent
        '...Do stuff.
        End Sub

        If THAT is what they mean, why put all of those events in a collection (a Class), instead of just calling them all out in

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Try reading this old article on MSDN.[^] Truthfully, I haven't used WithEvents for anything in about 10 years. I found that I prefer to wire up the events I need myself instead of relying on Handles.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        T 1 Reply Last reply
        0
        • L Lost User

          treddie wrote:

          If so, why use the keyword "WithEvents at all? Why not just,

          "VB6"

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          T Offline
          T Offline
          treddie
          wrote on last edited by
          #4

          Do you mean that it is a left-over from vb6?

          L 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Try reading this old article on MSDN.[^] Truthfully, I haven't used WithEvents for anything in about 10 years. I found that I prefer to wire up the events I need myself instead of relying on Handles.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            T Offline
            T Offline
            treddie
            wrote on last edited by
            #5

            Thanks for the links. It's taking a while, since I have to fit reading them into my schedule. I am in the middle of Article 2.

            1 Reply Last reply
            0
            • T treddie

              Do you mean that it is a left-over from vb6?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              It was already there[^], yes :)

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups