This is easy enough to do with an EditField subclass where you
trap and filter the key codes in the KeyDown() event. Here's what I
use to implement an "IntegerOnlyEditField":
Function KeyDown(Key As String) As Boolean
Dim theChar As String
theChar = Uppercase(Key)
If (theChar = ChrB(8)) Then
// 'Normal' Delete key (not the one under the Insert key)
Return False
End IF
If (theChar = ChrB(9)) Then
// <Tab>
Return False
End If
If (theChar = ChrB(28)) Then
// Left-arrow key
Return False
End If
If (theChar = ChrB(29)) Then
// Right-arrow key
Return False
End If
If (theChar = ChrB(127)) Then
// 'Del' delete key (the one under the Insert key)
Return False
End If
If (((theCHar >= "0") And (theChar <= "9")) Or (theChar = "-")) Then
If (theChar = "-") And (InStr(Me.Text, "-") = 0) And
(Me.SelStart = 0) Then
Return False
End If
If ((theChar >= "0") And (theChar <= "9")) Then
Return False
End If
End If
Return True
End Function
BTW, I also put the following in:
Sub GotFocus()
Me.SelStart = 0
Me.SelLength = Len(Me.Text)
GotFocus
End Sub
and I provide a New Event GotFocus(). This is optional if you want
your EditField to auto-select its text when it gets the focus.
Otherwise you can leave out this part.
HTH!
On Jun 30, 2009, at 2:25 PM, Markus Winter wrote:
Hi,
is there a mask that allows only positive and negative numbers to
be entered
in an Editfield?
I only manage positive numbers via 9999.9999 but both
#9999.9999 and -9999.9999 do not work …
Thanks
Markus
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|