Results 1 to 4 of 4

Thread: VB.NET 2005 - Function based on timer.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2010
    Location
    Ontario, Canada
    Posts
    55

    VB.NET 2005 - Function based on timer.

    I can't seem to get one of my functions to work based on a timer. Every tick of the timer, I'm trying to call a function which will start periodically taking screen shots until the 'Finish' button is pressed. However, I've run into numerous errors and wondered if anyone could give me any insight or suggestions. Here is what I have so far...

    Code:
    Public Class Form1
    
        Dim ssTimer1 As Timer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.ssTimer1.Enabled = False
        End Sub
    
        Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    
            ssTimer1.Interval = 10000
            ssTimer1.Enabled = True
    
            AddHandler ssTimer1.Tick, AddressOf RunAC
    
        End Sub
    
        Public Sub RunAC()
            < yata yata yata code code code>
        End Sub
    End Class
    One of the errors included "Public Sub RunAC() does not have the same signature as delegate". This might be really obvious, I'm a recent Computer Programmer / Analyst graduate with intermediate VB.net experience. Any help is appreciated.
    Last edited by stronius; Feb 9th, 2010 at 10:03 AM.

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: VB.NET 2005 - Function based on timer.

    You need your event sub to have the same signature (parameters) as the event itself for it to be handled so this:
    Code:
    Public Sub RunAC()
            < yata yata yata code code code>
        End Sub
    becomes:
    Code:
    Public Sub RunAC(ByVal sender As System.Object, ByVal e As System.EventArgs)
            < yata yata yata code code code>
        End Sub
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: VB.NET 2005 - Function based on timer.

    Why do you have to declare you timer in code (and never instantiate it) ? And the RunAC sub doesn't have the same signature of a timer.tick event?

    It would be a lot simpler if you just drop a timer from the toolbox to your form in the designer and then double click on the timer's icon to create a timer.tick event handler for it.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2010
    Location
    Ontario, Canada
    Posts
    55

    Re: VB.NET 2005 - Function based on timer.

    Got it working. Thanks guys. Yeah I forgot all about .NET having a timer control. After adding the Timer control, it made things a lot easier.

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