dbTalk Databases Forums  

Trapping for non "number"

comp.databases.paradox comp.databases.paradox


Discuss Trapping for non "number" in the comp.databases.paradox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Craig
 
Posts: n/a

Default Trapping for non "number" - 02-26-2009 , 05:58 AM






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



Reply With Quote
  #2  
Old   
Jim Giner
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 07:52 AM






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.
"Craig" <craig.futterman (AT) nospam (DOT) comcast.net> wrote

Quote:
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




Reply With Quote
  #3  
Old   
Steven Green
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 08:19 AM



Quote:
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

"Craig" <craig.futterman (AT) nospam (DOT) comcast.net> wrote

Quote:
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



Reply With Quote
  #4  
Old   
Tony McGuire
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 08:20 AM



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


Craig wrote:
Quote:
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





Reply With Quote
  #5  
Old   
Jim Moseley
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 10:02 AM




Craig,

Quote:
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


Reply With Quote
  #6  
Old   
Craig
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 04:22 PM



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




"Jim Moseley" <jmose (AT) mapson (DOT) attglobal.net> wrote

Quote:
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



Reply With Quote
  #7  
Old   
Liz McGuire
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 04:47 PM




Perhaps a trap in the field's error event:

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

Liz


"Craig" <craig.futterman (AT) nospam (DOT) comcast.net> wrote:
Quote:
Is it possible to intercept that
message so I can make it more noticeable?


Reply With Quote
  #8  
Old   
Craig
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 06:27 PM



Liz, Fantastic!
That worked.
Is there a list of all these errorcodes anywhere?
Thanks again,
Craig

"Liz McGuire" <liz (AT) paradoxcommunity (DOT) com> wrote

Quote:
Perhaps a trap in the field's error event:

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

Liz


"Craig" <craig.futterman (AT) nospam (DOT) comcast.net> wrote:
Is it possible to intercept that
message so I can make it more noticeable?




Reply With Quote
  #9  
Old   
Liz McGuire
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 07:32 PM



ProView has a shortcut for listing RTL Errors. I used that. There are
methods in ObjectPAL to list RTL errors, methods, constants, etc.

Liz


Craig wrote:
Quote:
Liz, Fantastic!
That worked.
Is there a list of all these errorcodes anywhere?
Thanks again,
Craig

Reply With Quote
  #10  
Old   
Craig
 
Posts: n/a

Default Re: Trapping for non "number" - 02-26-2009 , 08:03 PM



I have ProView. I'll look there.
Thanks again,
Craig
"Liz McGuire" <liz (AT) paradoxcommunity (DOT) com> wrote

Quote:
ProView has a shortcut for listing RTL Errors. I used that. There are
methods in ObjectPAL to list RTL errors, methods, constants, etc.

Liz


Craig wrote:
Liz, Fantastic!
That worked.
Is there a list of all these errorcodes anywhere?
Thanks again,
Craig



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.