Lukker spørsmålet da jeg fikk svar på en annen internettside.
http://mailman.anu.edu.au/mailman/listinfo/approachJeg stilte følgende spørsmål:
I try to check what key is pressed when a field in a form got the focus?
I use:
Sub Keydown(Source As Fieldbox, Charcode As Long, Repeats As Integer, _
Flags As Integer, Overridedefault As Integer)
End Sub
The problem:
How to check what key is pressed, and if a special key is pressed
( the "+" ), then I want to cancel the key before the field got the value.
****************************************************************
Det første svaret jeg fikk:
In Approach you have to remove the char from the field as soon as the
key is released. Therefore, use the Keyup event because when Keydown
fires, the char isn't entered in the field yet. Second problem is that
you can't modify a fieldbox's properties while it has focus. Draw a line
object just next to the field, name it lneTmp say, and give it the same
colour as the form background so it can't be seen. Then this will remove
any + signs entered into the field:
Sub Keyup(Source As Fieldbox, Charcode As Long, Repeats As Integer,
Flags As Integer, Overridedefault As Integer)
If Charcode = 107 Then
CurrentView.Body.lneTmp.SetFocus
Source.Text = Left$(Source.Text, Len(Source.Text) - 1)
Source.SetFocus
Sendkeys "{END}"
End If
End Sub
If you type a long sequence like 66++5+55+++6++66+66++665++ etc ~very~
quickly you may defeat it but for normal data entry it should be fine.
Note this only traps the + keystroke, not a + pasted into the field.
Paul Bent
Northwind IT Systems
www.northwindit.co.uk******************************************************
MITT 2. SPØRSMÅL:
Paul, Thanks for the answer.
Before I try to use your code. I'll ask you if it possible to do it in
an
easier way, when you know that.
When the keypress is the "+" nothing should be enterd in the field. The
field should keep it's standardvalue. (1)
You wrote. " when the keydown fires, the char isn't enterd in the field
yet."
But is it possibele to check the Charcode before the characther is
enterd
in the field?
Or do I have to make a line object as you said? ( I have to do this for
a
lot of fields )
Øyvind
************************************************************
DET 2. SVARET
Keydown returns the Charcode just before it appears in the field but
there is no way to intercept the character and discard it. In Visual
Basic the parameter is KeyAsc and you can set it to 0 but this doesn't
work in Approach.
You only need to create one line object and one global sub to serve all
fields:
Public Sub sRemovePlus( _
dspObj As Display, Byval intCharCode As Integer)
If intCharcode = 107 Then
With dspObj
CurrentView.Body.lneTmp.SetFocus
.Text = Left$(.Text, Len(.Text) - 1)
.SetFocus
Sendkeys "{END}"
End With
End If
End Sub
Then paste this statement into the Keyup event of each fieldbox to call
the sub:
sRemovePlus Source, Charcode
Paul Bent
Northwind IT Systems
www.northwindit.co.uk