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: Tom Benson <tombenson@mac.com>
Date: Wed, 01 Jul 2009 13:26:37 +1000
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <17EF5820-972F-48B3-85EA-B54B1E8F9C5B@satx.rr.com>
References: <C6703331.57971%markus_winter@online.de> <17EF5820-972F-48B3-85EA-B54B1E8F9C5B@satx.rr.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Personal preference, but I find this is much easier to read if you do it like this:

theChar = Uppercase(Key)

select case ChrB(theChar)

        case 8    //delete

        case 127   // forward delete

        case 28     //left arrow

        case 29    //right arrow
        
        case else
                //stick your numerical detection here...
end select




- Tom Benson
---------------------------------------------------------------
Custom Controls & Code Libraries
for REALbasic version 5.5 and up

http://www.qedit.com.au




On 01/07/2009, at 10:27 AM, William Squires wrote:

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>


_______________________________________________
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>