Strings and Arrays are ALWAYS passed as reference (not BYVAL) to any SUB/FUNCTION call according to my findings. Had a similar problem a while back, and did investigate into it as far as possible....
Which makes the case for ON TIMER that much more curious. It is NOT ALWAYS.
http://qb64.org/wiki/ON_TIMER(n)
[ This attachment cannot be displayed inline in 'Print Page' view ]
I think Rho has hit the nail on the head with: “Strings and Arrays are ALWAYS passed as reference (not BYVAL) to any SUB/FUNCTION”.
ON TIMER *only* accepts values being passed to it BYVAL, (as per the screen shot bplus provides points out), so it can’t accept strings or arrays as a parameter type.
I have never used ON TIMER.
The help said this
The ON TIMER statement sets up a timed event to be repeated at specified intervals throughout a program when enabled
So, is it like an interrupt?
If so, I understand the above post. You might be in a function or subroutine somewhere that does not have the scope of this parameter, then it makes sense that it can only take shared vars and literals.
What kinds of things do you use ON TIMER for?
Its useful in games programming. Interrupts are kinda mysterious. Think of two or more programs running concurrently. I think about this hot wheel timer I want to write, the two events you can't miss are when the car enters the first gate, and when it enters the 2nd gate and how much time has elapsed. Basic alone might be too slow to see these events if you need accuracy to 1/1000th a second, interrupts can help with that. I'm still not to where I have done one yet tho.
I'm sure the mind of a juggler appreciates them. So many tasks going on simultaneously :-)
Now think about the nature of ON TIMER, you define a time interval for the function call, but who says that your program is right executing anywhere in your main module when the interval is elapsed and the DoSomething(X) function is called.
What happens, when your program is executing within any of your SUBs or FUNCTIONs when the timer is ready to call DoSomething(X)? What is passed then? Because variable X is not known in your SUBs/FUNCs unless SHARED or maybe defined as a local X within the SUB/FUNC.
RhoSigma wrote:
I doubt the whole concept of passing arguments to a timer called SUB works well at all for a senseful use.
The passed variable must be initialized prior the ON TIMER statement, otherwise it won't work, hence the concept is pretty useless for passing any variable which changes during runtime...