Plan_OK
Member
- Joined
- Aug 21, 2023
- Messages
- 24
- Programming Experience
- 1-3
I have an infinite Do - Loop that invokes an audio file. There is a Button control on the screen that, when pressed, causes the program flow to continue.
Changing the flow, however does not interrupt the loop which continues in the background still executing the sound file which cannot be interrupted.
I have temporarily replaced the Do-Loop loop with a For-Next loop with fixed iteration, however, not being able to control the number of repetitions, but it is not the best.
I attach part of the listing. Thank you.
I can intercept the left click with:
But I don't know how to control the exit from the loop.
How to intercept the button click press from within the loop to interrupt it?
Thank you.
Changing the flow, however does not interrupt the loop which continues in the background still executing the sound file which cannot be interrupted.
I have temporarily replaced the Do-Loop loop with a For-Next loop with fixed iteration, however, not being able to control the number of repetitions, but it is not the best.
I attach part of the listing. Thank you.
VB.NET:
For volte = 1 To 5 ' prec: Do
If chkSuono.Checked Then Parla("tang")
For dimChar = 10 To 30
lblPrimaRegione.Font = New Font(lblPrimaRegione.Font.Name, dimChar, FontStyle.Bold)
Ritardo(22)
Next
For dimChar = 30 To 10 Step -1
lblSecondaRegione.Font = New Font(lblSecondaRegione.Font.Name, dimChar, FontStyle.Bold)
Ritardo(22)
Next
For dimChar = 30 To 10 Step -1
lblPrimaRegione.Font = New Font(lblPrimaRegione.Font.Name, dimChar, FontStyle.Bold)
Ritardo(22)
Next
For dimChar = 10 To 30
lblSecondaRegione.Font = New Font(lblSecondaRegione.Font.Name, dimChar, FontStyle.Bold)
Ritardo(22)
Next
Next ' prec: Loop
Public Sub Ritardo(ByVal TIME_RITARDO As Integer)
Dim StartTime As Date = Now
Do
Application.DoEvents()
Loop Until (Now - StartTime).TotalMilliseconds > TIME_RITARDO
End Sub
Public Sub Parla(file)
stPercorsoMusica = Application.StartupPath() & "\" & file & ".mp3"
mciSendString("close " & stAliasMusica, CStr(0), 0, 0)
mciSendString("Open " & Chr(34) & stPercorsoMusica & Chr(34) & " alias " & stAliasMusica, CStr(0), 0, 0)
mciSendString("play " & stAliasMusica, CStr(0), 0, 0)
End Sub
VB.NET:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If GetAsyncKeyState(Keys.LButton) <> 0 Then
' ????
' ????
End If
End Sub
But I don't know how to control the exit from the loop.
How to intercept the button click press from within the loop to interrupt it?
Thank you.