Domanda

i want to display a character in an inputbox: dot . on click and dash - on long click. For instance, holding left click for 2 seconds will display dash instead of dot.

i have tried this on double click, here is my code:

Private Sub input_Click()
Me.input.Value = "." + Me.input.Value
End Sub

Private Sub input_DblClick(Cancel As Integer)
Me.input.Value = "-" + Me.input.Value
End Sub

the problem here is that when i double click it will pass thru click and display dot and dash when it is suppose to display dash only.

i'd like to add that i need to use only left click on this. no keyboard, no right click.

that's why my idea is to use either click for dot and double click for dash, or click and long click.

I have an idea of having if statement on VBA and check if its a single click or double without using the double click event.

È stato utile?

Soluzione

Define in the header of form's module the following variables:

    Private isMouseKeyPreessed As Boolean
    Private timeMouseKeyPreessed  As Date

then define MouseUp and MouseDown events for textbox named input (by the way it is bad name, because input is reserved word):

    Private Sub input_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = acLeftButton Then
            isMouseKeyPreessed = True
            timeMouseKeyPreessed = Now
        End If
    End Sub

    Private Sub input_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim Delta  As Double
        Dim symbol As String

        If Button = acLeftButton Then
            isMouseKeyPreessed = False
            Delta = Now - timeMouseKeyPreessed
            If Delta > 0.00002 Then
                ' 0.00002 - is a value to tune up to get exactly 2 seconds
                ' it should be about
                ' cdbl(timeserial(0,0,2)-timeserial(0,0,0))
                symbol = "-"
            Else
                symbol = "."
            End If
            Me.input.Value = symbol & Me.input.Value
        End If

    End Sub
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top