realbasic-nug
[Top] [All Lists]

Re: Editfield mask for neg and positive numbers?

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Editfield mask for neg and positive numbers?
From: William Squires <wsquires@satx.rr.com>
Date: Tue, 30 Jun 2009 19:27:20 -0500
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <C6703331.57971%markus_winter@online.de>
References: <C6703331.57971%markus_winter@online.de>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
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>


<Prev in Thread] Current Thread [Next in Thread>