-
Jun 22nd, 2018, 11:54 PM
#1
Thread Starter
Member
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.
-
Jun 23rd, 2018, 12:32 AM
#2
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:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click DoSomething() End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick DoSomething() End Sub Private Sub DoSomething() 'Preform some action here. End Sub
-
Jun 23rd, 2018, 12:40 AM
#3
Thread Starter
Member
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?
-
Jun 23rd, 2018, 01:10 AM
#4
Thread Starter
Member
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
-
Jun 23rd, 2018, 02:15 AM
#5
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|