I’d like to know if there is a way to call a timer through a function. This function itself is called through an automated timer that is activated when the form loads.
Function callTimer(ByRef var1 As Integer, ByVal var2 As Integer)
'statements()
Media.SystemSounds.Beep.Play() 'to ensure that it is called
Call otherFunction(ByRef var3 As Integer) <-- how do you do this??
Return var1
End Function
I want to know how this can be done. VB gives me an error when I try this or something like this.
Thanks all!
What @competent_tech was saying is that you’re defining a function within a function, which is illegal. You want to call the function, not define it. An example of this would be like so:
It seems like you might be a little confused with calling a function versus defining a function. Before you can use a function it must be defined, like my example code above.
Another thing to get a better handle on is the usage of ByRef versus ByVal. ByRef passes a reference to an address in memory. What this means is that any changes to the variable within a function will persist outside of the function. ByVal, however, will not persist outside of the function and the value before being passed to the function will be the same as after the function call. Here is an example of that:
Result:
This ByRef/ByVal example can be seen at this link. It’s worth looking more into if you’re still confused.
EDIT: This edit includes information regarding invoking a timer in VB.NET.