Delay in Loops?

I was wondering if there was any way to put a delay in a loop. Specifically, I’m looping through an array of words and I want to adjust the speed at which the words are spoken. If it’s in the documentation, I’m not seeing it.

Thanks!

speak("Hello") App.SleepCurrentThread(1000) speak("world")

A loop may freeze the UI ; you may want to use a timer instead to send the words to Speak.

Thanks for the input guys! Nothing’s working. Don’t worry, I’ll figure something out.

The timer should work.

Put the sentences to say in an array, and have something like this in the Action event of a multiple timer :

[code]Static pointer as integer

If pointer <= sentences.ubound
Speak sentences(pointer)
Pointer = Pointer + 1
else
me.Mode = Timer.ModeOff
end if
[/code]

You control the interval with the timer period.

That worked Michel. Very much appreciated, thank you.

…And sorry for marking my comment as the answer. I don’t know how that happened but it was purely unintentional. Thanks again!

It’s alright, Robert. Glad to have been of help :slight_smile:

Thanks, Michel. One problem though; I’m not able to get the timer to fire again. Searching the discussions, I found that this was a known bug back in 2015. Has this persisted? Below is one of the many things I’ve tried with no success:

If pointer <= combinedVocab.ubound Then Speak combinedVocab(pointer) Pointer = Pointer + 1 else Timer1.Mode = Timer.ModeOff TextArea1.Text = "" Timer1.Mode = Timer.ModeMultiple // Attempt to reset the timer. End If End If

What do you want to obtain exactly ?

from what I see, you are trying to restart the timer, but you don’t reset pointer to zero.

And I don’t really see the logic of setting mode to off to set it to multiple two lines later. You might as well not change mode at all.

BTW, I checked, the timer does restart just fine.

That was the problem; I wasn’t setting pointer back to zero. In regards to setting mode to multiple almost immediately, it’s the only way I know of to get the timer to restart after mode was set to off. But you’re right; not changing mode at all, and then adding a stop event is a better way to go. Everything is working great now. Thanks again, Michel!