I’m trying to use a timer in a module and haven’t much clue on how it works…
I have added a timer to the module, then added an eventhandler action to it. And last made it readble/writable (just guessing that it is needed).
How do I address the timer from a Method in the same module?
If I try to do this in the Method:
Timer1.Mode=Timer1.Modesingle
or fiddling a bit by random and write (or other variations):
Module1.Timer1.Mode=Module1.Timer1.Modesingle
It results in an error:
This item does not exist
Timer1.Mode=Timer1.Modesingle '(with “Mode” highlighted)
I have searched, but not really found anything on this.
I am trying to group parts of code in order to make the programs more tidy. In this case I was trying to move everything that is involved in sampling a block of sound samples then processing them, into a Module. A module that I was supposed to be able to use in other programs by just copying the module. Timers are part of the routines.
Are you saying that I can not put a timer into a module? Then why can I drag one into the module? I can’t put the container control inside the Module either, it seems
If a module can not do what I want. Is there anything that can?
I just want to gather code in a convenient way.
I need to start a process (involving methods, properties, timers etc) and then to be able read the result. No other interaction until finished. Just start process -> read from memoryblock or array when finished. Keeping all these methods, properties and timers inside their own box so it is easier to find my way around among the rest of the code and to make it easier to re-use it in other programs I might need it.
I could compile it as a separate program or console app and run that (instead of what I thought could be gathered inside the module), but doesn’t feel perfect and I will have pick up the data via UDP/TCP, read from a file etc? No was to use arrays or memoryblocks. Hm. I don’t know…
Create a property called ‘Timer1’ (for this example)
Code an instance of your timer into a method within a module.
[code]Timer1= New Timer
Timer1.Period = 1000
Timer1.Mode = Timer.ModeMultiple
AddHandler WindowTimer.Action, AddressOf Timer1Action[/code]
3. Create a method called ‘Timer1Action’ (you can change this if you wish - provided that you change the ‘AddressOf Timer1Action’ also
4. Add the parameter as ‘sender as timer’.
Thanks! It worked. I don’t know how I would have found out where to look and how to solve this, without the help of this forum… Again starting from the reference was no help and I had no clue what to search for except +xojo +module +timer…
Just one small mistake in the example, though (if anyone else needs the solution):
[quote=140597:@Roger Jönsson]Thanks! It worked. I don’t know how I would have found out where to look and how to solve this, without the help of this forum… Again starting from the reference was no help and I had no clue what to search for except +xojo +module +timer…
Just one small mistake in the example, though (if anyone else needs the solution):
[quote=140626:@Oliver Scott-Brown]No. This is not a mistake. You can name the method ‘Timer1Action’ whatever you wish and you can name the timer whatever you wish.
This is no error.
I copied literally took this code from the docs and changed WindowTimer to Timer1.[/quote]
Actually, Oliver, your example does indeed have an error if you are trying to create a handler for Timer1. You wrote:
[code]Timer1= New Timer
Timer1.Period = 1000
Timer1.Mode = Timer.ModeMultiple
Yes it is briefly mentioned in chapter 3, but it wouldn’t have helped with the questions I had…
It is true that I will learn with experience, but I have a hard time finding way in the documentation. There is probably some sort of Logic to it, that I still have to discover. If it is just me, but often when I try to lock something up, there are black holes (descriptions feels incomplete) and new questions are generated, by lack of info and not knowing what goes on, on the inside. Probably this gets easier with time, but I do feel that I lack a good solid reference.
[quote=140667:@Roger Jönsson]Yes it is briefly mentioned in chapter 3, but it wouldn’t have helped with the questions I had…
It is true that I will learn with experience, but I have a hard time finding way in the documentation. There is probably some sort of Logic to it, that I still have to discover. If it is just me, but often when I try to lock something up, there are black holes (descriptions feels incomplete) and new questions are generated, by lack of info and not knowing what goes on, on the inside. Probably this gets easier with time, but I do feel that I lack a good solid reference.[/quote]
I think the docs are an excellent reference. It has some confusing gaps that confuse me sometimes. I just ask my questions on the forums and get a quick answer.