Is [(FillInTheBlankMorph request: ' ) asNumber] on: Error do: [];necessary

Frank Shearar Frank.Shearar at rnid.org.uk
Thu Dec 30 10:08:52 UTC 2004


Thomas Koenig <tomkoenig at mindspring.com> wrote:
> 
> I have a number of places in the code that look something like this:
> [id _ (FillInTheBlankMorph request: 'Enter the id of the post you''d
> like to jump to:' translated) asNumber ]
> 		 on: Error
> 		 do: [ self inform: 'That is not a valid number.'
> translated.
> 		        ^ nil ].
> Yet no mater what I key into the morph I don't trigger an error (don't
> see the error  message.)  
> Is there a good argument for keeping the error block?  If so can you
> suggest an test condition that would trigger it.
> 
> I'm inclined to remove this code, because it appears to add only
> complexity. 

I've played around with String>>asNumber. Here's what I find:

'1' asNumber -> 1
'a' asNumber -> 'Error: At least one digit expected here'
'1a' asNumber -> 1
'%' asNumber -> 'Error: At least one digit expected here'
'16rff' asNumber -> 'Error: At least one digit expected here'
'16rFF' asNumber -> 255

Personally, I'd prefer to see something like

  id := FillInTheBlankMorph requestNumber: 'foo' translated

where #requestNumber: would do one of the following:
* re-asked the user until they entered a valid number
* prevented the user entering anything other than a valid number (by highlighting the text as red if it's invalid, or not letting the user enter certain characters like )(&^%$"!# etc)

Now, I'm not sure what #requestNumber should return if the user presses cancel. Maybe #requestNumber: should do this

requestNumber: aString
    ^self requestNumber: aString default: nil

and #requestNumber:default: then returns some default value if the user presses cancel.

frank


*******************************************************************
This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to
whom they are addressed. Any views or opinions expressed
are solely those of the author and do not necessarily represent
RNID policy.
If you are not the intended recipient you are advised that any
use, dissemination, forwarding, printing or copying of this
email is strictly prohibited.
If you have received this email in error please notify the RNID
Helpdesk by telephone on: +44 (0) 207 296 8282.
The Royal National Institute for Deaf People
Registered Office 19*23 Featherstone Street
London EC1Y 8SL No. 454169 (England)
Registered Charity No. 207720
********************************************************************




More information about the Squeak-dev mailing list