[quote=143149:@Rami Hassan]Hi, so I’ve been using Xojo for a day and I’m loving it.
I’ve worked out that using a timer allows me to use pauses efficiently, but is there a way I can pause code in a code not in a timer, for example a TextLabel; I want it to do something like this (pseudocode):
wait a second
wait a second
Is there a way I can do this?
At this point of the discussion, I feel it is necessary to make the difference between procedural code, and event driven code.
In the past, since the early days of Basica and AppleSoft basic, a program started at line 10 and went on in a procedural way one line after the other. So in essence what you want to do is go one line after the other and wait in between, just like you would have done 30 years ago.
Xojo and other modern languages proceed otherwise. Instead of going one line after the other, they use subprograms which execute in event handlers upon actions taken by the user of the program. Typically, when the user clicks it triggers the execution of the button Action event. There is no notion of wait because intrinsically the program simply does nothing until an event happens.
A timer creates an event at intervals. Instead of waiting one second, it does something every second (or any needed interval). So what you want to do will be carried out in the modern event driven model not as “do this, wait, do that, wait”, and so on, but as “do something every second”.
Your example could be carried out very easily by a timer Action event.
- Drop a timer on the window
- Drop a TextArea1
- In the Timer, put this Action event :
static counter as integer = 1
select case counter
TextArea1.Text = TextArea1.Text + "Hello "
TextArea1.Text = TextArea1.Text + "World."+EndofLine
TextArea1.Text = TextArea1.Text + "How are you ?"
counter = counter + 1
Contrary to the wait() or app.SleepCurrentThread() model, you can do all sorts of things in between the events. Just like in real life, you can go have a beer during commercials on TV. Move things on screen for the user entertainment, do housekeeping in your program, and so on.
I strongly recommend you try forgetting the old procedural model. Everything in a Xojo program is event driven. It will be a lot easier for you to program in Xojo if you embrace this model early on.