Results 1 to 5 of 5

Thread: Is there a way to use Timer1_Tick manually in different sub?

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    51

    Arrow Is there a way to use Timer1_Tick manually in different sub?

    I have a program which uses a Timer1_Tick sub. However, I would like to manually configure this Timer in a function.

    For example,

    Code:
    Private Function TestFunc()
        Timer1_Tick(whatever)
        Timer1.Interval = 100
    End Function
    However, when I try this method, I get an error under Timer1_Tick inside my function which says:

    Argument not specified for parameter 'e' of 'Private Sub Timer1_Tick(sender As Object, e As EventArgs)
    What am I doing wrong with this?

    Note that Timer1_Tick sub is in my code. However, if I remove it, I get an error saying Timer1_Tick isn't declared.
    Please comment for any more information.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,689

    Re: Is there a way to use Timer1_Tick manually in different sub?

    While you can do it, you should never call an event handler directly. If you want to perform the same action when a Timer Ticks and at other times too, the thing to do is to put that action in its own method and then call that method from the Tick event handler of the Timer and also from wherever else you need to, e.g.
    vb.net Code:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.     DoSomething()
    3. End Sub
    4.  
    5. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    6.     DoSomething()
    7. End Sub
    8.  
    9. Private Sub DoSomething()
    10.     'Preform some action here.
    11. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    51

    Re: Is there a way to use Timer1_Tick manually in different sub?

    Ok, thanks.

    I've tried this code for alt()

    Code:
        Private Sub alt()
            GetMD5String(strFilename)
        End Sub
    but it just says strFileName isn't declared.

    Why? Also, it tries to autocorrect me to strFileName:=


    Could their be an easier method to refresh a function instead of having to use a TImer?

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2018
    Posts
    51

    Re: Is there a way to use Timer1_Tick manually in different sub?

    Sorry, forgot to mention this is my function name:


    Code:
      Private Function GetMD5String(ByVal strFilename As String) As String

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,689

    Re: Is there a way to use Timer1_Tick manually in different sub?

    I think that you need to stop, learn the basics of VB.NET programming first, then put some thought into what you're doing and then try writing this code again. What is the point of that 'alt' method at all? Think about what that GetMD5String method is supposed to do. It is supposed to receive the path of a file, calculate the MD5 hash of that file and the return it. In your 'alt' method you don't have the path of a file to calculate the MD5 hash of and you're not doing anything with the result even if you did, so what is the point? Instead of throwing stuff at the wall to see what sticks, take the time to actually plan something. Work out exactly what you want your code to do before you start writing it because you're just writing nonsense at the moment. For instance, this:
    Could their be an easier method to refresh a function instead of having to use a TImer?
    makes no sense at all. There's no such thing as refreshing a function. If you don't understand what you're actually trying to do then you have no hope of actually doing it and also no hope of explaining it to us to help you do it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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