Sub Label1_Click
If WaitClick = 1 Then
WaitClick = 2
Return
End If
If WaitClick <> 0 Then Return
WaitClick = 1
Sleep (200)
If WaitClick = 1 Then
Log ("Single")
Else
Log ("Double")
End If
WaitClick = 0
End Sub
In this way the double click log would appear twice, because twice it enters Label1_ClickI made following experiment
I declared Dim WaitClick As Byte in Process_Globals and added following sub
B4X:Sub Label1_Click If WaitClick = 1 Then WaitClick = 2 Return End If If WaitClick <> 0 Then Return WaitClick = 1 Sleep (200) If WaitClick = 1 Then Log ("Single") Else Log ("Double") End If WaitClick = 0 End Sub
LastClick as long ' in Globals
Sub Label1_Click
If DateTime.Now-LastClick<300 Then
Log("Double Click")
Else
Log("Single Click")
End If
LastClick=DateTime.Now
End Sub
Sub Label1_Click
If DateTime.Now-LastClik<300 Then
Log("Double Click")
LastClik=-1
Else
LastClik=DateTime.Now
Sleep(300)
If LastClik<>-1 Then
Log("Single Click")
End If
End If
End Sub
In this way the double click log would appear twice, because twice it enters Label1_Click
If WaitClick = 1 Then
WaitClick = 2
Return
End If
You're right, I did not notice the return.@Star-Dust
It's not so and you obviously did not try my code. A logic maybe a little strange. But I will try to explain.
When user clicks first time (WaitClick = 0), the program sets WaitClick = 1 and falls asleep per 200 ms.
What happens further ...
a) If user does not click during sleep period, the subroutine wakes up, logs "Single" (because WaitClick = 1) and returns initial state (WaitClick = 0)
b) user clicks one time during sleep period.
In this case the program sets WaitClick = 2 and exits.
Note, that similar actions do not have relation to first instance, where we set Sleep (200).B4X:If WaitClick = 1 Then WaitClick = 2 Return End If
First instance of Sub wakes up, sees WaitClick = 2, reports "Double" and returns initial state (WaitClick = 0)
c) user clicked more than one time during sleep period.
In this case rhe subroutine simply ignores click (when WaitClick = 2, a fragment If WaitClick = 1 Then does not work, but works If WaitClick <> 0 Then Return)
Sub Label1_Click
If DateTime.Now-LastClick<300 Then
Log("Double Click")
Else
Log("Single Click")
End If
LastClick=DateTime.Now
End Sub
I believe you have not tried my code.I am sorry, but
B4X:Sub Label1_Click If DateTime.Now-LastClick<300 Then Log("Double Click") Else Log("Single Click") End If LastClick=DateTime.Now End Sub
is not a solution.
Imagine that last click was at 12:00:00.000
Then user clicks twice at 12:00:01.000 and 12:00.01.150.
What will report your subroutine ? "Single Click", "Double Click". Meanwhile this is simply "Double Click" (150 ms between clicks)