Discussion:
Trapping for non "number"
(too old to reply)
Craig
2009-02-26 11:58:28 UTC
Permalink
I have a field in a table which is set as a number field.
The user can only insert whole numbers such as 1 or a decimal such as .5
(the user can also do 1.5 etc..)
THere are only certain decimals which are allowed and I have a method which
checks that. Not a problem.
I am concerned that the user might try to insert a fraction such as "1/2".
I would like to trap for that PRIOR to the method which checks for the
proper decimals which is triggered in changevalue.
How can I trap for that?

Thanks in advance,
Craig
Jim Giner
2009-02-26 13:52:14 UTC
Permalink
First - whole numbers do not include ".5". But since you say you want them
to enter either integers (whole numbers) or numbers represented in decimal
form (rather than fractional), then just add this check to your changevalue
method.

Might take some work, but can't you use a picture that requires "any number
of digits" followed by "." and "any number of digits", making the dot and
the second string of digits optional in your pic? I"m not a master of pics,
so I can't even offer up the syntax.
Post by Craig
I have a field in a table which is set as a number field.
The user can only insert whole numbers such as 1 or a decimal such as .5
(the user can also do 1.5 etc..)
THere are only certain decimals which are allowed and I have a method
which checks that. Not a problem.
I am concerned that the user might try to insert a fraction such as "1/2".
I would like to trap for that PRIOR to the method which checks for the
proper decimals which is triggered in changevalue.
How can I trap for that?
Thanks in advance,
Craig
Steven Green
2009-02-26 14:19:25 UTC
Permalink
Post by Craig
I am concerned that the user might try to insert a fraction such as "1/2".
"1/2" is text, not number.. if your field is numeric, they can't enter
text..

--

Steven Green - Myrtle Beach, South Carolina USA

http://www.OasisTradingPost.com

Oasis Trading Post
- Collectibles and Memorabilia
- Vintage and Custom Lego Creations

Diamond Software Group
- Paradox Sales and Support

Diamond Sports Gems
- Sports Memorabilia and Trading Cards
Post by Craig
I have a field in a table which is set as a number field.
The user can only insert whole numbers such as 1 or a decimal such as .5
(the user can also do 1.5 etc..)
THere are only certain decimals which are allowed and I have a method
which checks that. Not a problem.
I am concerned that the user might try to insert a fraction such as "1/2".
I would like to trap for that PRIOR to the method which checks for the
proper decimals which is triggered in changevalue.
How can I trap for that?
Thanks in advance,
Craig
Tony McGuire
2009-02-26 14:20:25 UTC
Permalink
You can test whether a value is valid for a field using 'isValid()'.

This is using a tcursor.



isValid Method

Reports whether the contents of a field are valid and complete.

Syntax

1. isValid ( const fieldName String, const value AnyType ) Logical
2. isValid ( const fieldNum SmallInt, const value AnyType ) Logical

Description

isValid reports whether the value specified in value conforms with field type
and validity checks for the field specified in fieldNum or fieldName. This
method allows you to determine whether a new field value is valid before you
attempt to post the record.

isValid returns True if value conforms to field type and validity checks;
otherwise, it returns False.


---------------
Tony McGuire
http://www.lostlore.com
Post by Craig
I have a field in a table which is set as a number field.
The user can only insert whole numbers such as 1 or a decimal such as .5
(the user can also do 1.5 etc..)
THere are only certain decimals which are allowed and I have a method which
checks that. Not a problem.
I am concerned that the user might try to insert a fraction such as "1/2".
I would like to trap for that PRIOR to the method which checks for the
proper decimals which is triggered in changevalue.
How can I trap for that?
Thanks in advance,
Craig
Jim Moseley
2009-02-26 16:02:40 UTC
Permalink
Craig,
Post by Craig
I have a field in a table which is set as a number field.
Assuming you mean that you have a form with the field, then you can check
what is entered by the field's keyChar() method. For example (untested of
course):

method keyChar(var eventInfo KeyEvent)
curChar = eventInfo.char()
if curChar >= "0" and curChar <= "9" then
else
; check for multiple '.'
if curChar = ".' then
oldVal = self.value
if oldVal.search(".") > 0 then
disableDefault
eventInfo.setErrorCode(canNotDepart)
msgStop("Error","Only one decimal allowed")
return
endif
else
disableDefault
eventInfo.setErrorCode(canNotDepart)
msgStop("Error","Invalid digit")
return
endif
endif
doDefault
endMethod
Craig
2009-02-26 22:22:54 UTC
Permalink
Jim, Steve and Tony
Thanks for your assistance.
What I didn't think of doing was starting with a Picture.
This refers to the number of pills the physician for each size pill
(Coumadin for anyone interested).
I created a new picture I called numbersOnly.
#[.5]
This allows the numbers 1 -9 and if you want to do a decimal, remember only
.5 (or 1/2 a pill), is allowed.
If the users wants 1.5 pills he will just hit the decimal place and it will
automatically put the .5 in. If he tries .3 it will make it .5 and if he
tries a "/", it will give a message at the bottom which says invalid
character and won't put anything in. Is it possible to intercept that
message so I can make it more noticeable?

Craig
Post by Jim Moseley
Craig,
Post by Craig
I have a field in a table which is set as a number field.
Assuming you mean that you have a form with the field, then you can check
what is entered by the field's keyChar() method. For example (untested of
method keyChar(var eventInfo KeyEvent)
curChar = eventInfo.char()
if curChar >= "0" and curChar <= "9" then
else
; check for multiple '.'
if curChar = ".' then
oldVal = self.value
if oldVal.search(".") > 0 then
disableDefault
eventInfo.setErrorCode(canNotDepart)
msgStop("Error","Only one decimal allowed")
return
endif
else
disableDefault
eventInfo.setErrorCode(canNotDepart)
msgStop("Error","Invalid digit")
return
endif
endif
doDefault
endMethod
Liz McGuire
2009-02-26 22:47:59 UTC
Permalink
Perhaps a trap in the field's error event:

if eventInfo.errorCode() = peNoPictureMatch then
msgStop("Hey","Bad Doctor!")
endIf

Liz
Post by Craig
Is it possible to intercept that
message so I can make it more noticeable?
Craig
2009-02-27 00:27:00 UTC
Permalink
Liz, Fantastic!
That worked.
Is there a list of all these errorcodes anywhere?
Thanks again,
Craig
Post by Liz McGuire
if eventInfo.errorCode() = peNoPictureMatch then
msgStop("Hey","Bad Doctor!")
endIf
Liz
Post by Craig
Is it possible to intercept that
message so I can make it more noticeable?
Liz McGuire
2009-02-27 01:32:52 UTC
Permalink
ProView has a shortcut for listing RTL Errors. I used that. There are
methods in ObjectPAL to list RTL errors, methods, constants, etc.

Liz
Post by Craig
Liz, Fantastic!
That worked.
Is there a list of all these errorcodes anywhere?
Thanks again,
Craig
Craig
2009-02-27 02:03:08 UTC
Permalink
I have ProView. I'll look there.
Thanks again,
Craig
Post by Liz McGuire
ProView has a shortcut for listing RTL Errors. I used that. There are
methods in ObjectPAL to list RTL errors, methods, constants, etc.
Liz
Post by Craig
Liz, Fantastic!
That worked.
Is there a list of all these errorcodes anywhere?
Thanks again,
Craig
Loading...