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. How can I add code to a timer object.

How can I add code to a timer object.

Scheduled Pinned Locked Moved Visual Basic
question
8 Posts 5 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.
  • C Offline
    C Offline
    Central_IT
    wrote on last edited by
    #1

    Hi, This is an easy one, I think. I have written a procedure behind a button e.g. Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click I want to call this procedure from a timer function, how is this done? Thanks in advance.

    L L D V 4 Replies Last reply
    0
    • C Central_IT

      Hi, This is an easy one, I think. I have written a procedure behind a button e.g. Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click I want to call this procedure from a timer function, how is this done? Thanks in advance.

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

      How would you call any subroutine?

      The best things in life are not things.

      1 Reply Last reply
      0
      • C Central_IT

        Hi, This is an easy one, I think. I have written a procedure behind a button e.g. Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click I want to call this procedure from a timer function, how is this done? Thanks in advance.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        1. why would you put code in a button click handler, if what you want is have it executed by a timer tick handler? 2. you can simulate a button being clicked by calling Button.PerformClick :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
        Please use <PRE> tags for code snippets, they improve readability.
        CP Vanity has been updated to V2.3

        1 Reply Last reply
        0
        • C Central_IT

          Hi, This is an easy one, I think. I have written a procedure behind a button e.g. Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click I want to call this procedure from a timer function, how is this done? Thanks in advance.

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

          You don't put the code in the Button Click event handler. You put code in its own Sub, then call it from the Button Click handler and the Timer Tick event handler.

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

          1 Reply Last reply
          0
          • C Central_IT

            Hi, This is an easy one, I think. I have written a procedure behind a button e.g. Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click I want to call this procedure from a timer function, how is this done? Thanks in advance.

            V Offline
            V Offline
            vivek_bhaskar
            wrote on last edited by
            #5

            just call btnProcess.PerformClick() in timer.tick event. or btnProcess_Click(sender, nothing) in timer.tick event.

            D 1 Reply Last reply
            0
            • V vivek_bhaskar

              just call btnProcess.PerformClick() in timer.tick event. or btnProcess_Click(sender, nothing) in timer.tick event.

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

              That's the very wrong way to do it. It's lazy and leads to other possible issues that can't be traced down easily. If there is code that needs to be executed from multiple places you stick it in its own method with a name that has meaning as to what the code does. You don't "hide" it inside an event handler.

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

              V 1 Reply Last reply
              0
              • D Dave Kreskowiak

                That's the very wrong way to do it. It's lazy and leads to other possible issues that can't be traced down easily. If there is code that needs to be executed from multiple places you stick it in its own method with a name that has meaning as to what the code does. You don't "hide" it inside an event handler.

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

                V Offline
                V Offline
                vivek_bhaskar
                wrote on last edited by
                #7

                its up to the developer to decide... and ofcourse the one who asked this question knows how to move all the statements in the button's click event to a sub-routine and call the same sub-routine in the button's click event. its that simple..let them do in their own way. can you describe why it is wrong way?

                D 1 Reply Last reply
                0
                • V vivek_bhaskar

                  its up to the developer to decide... and ofcourse the one who asked this question knows how to move all the statements in the button's click event to a sub-routine and call the same sub-routine in the button's click event. its that simple..let them do in their own way. can you describe why it is wrong way?

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

                  I already did.

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

                  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