Home > Archive > Programming with dBASE > November 2005 > unwanted character in a field









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author unwanted character in a field
Moses Hanna

2005-11-08, 9:24 am

Hi
I have a character field (charef)
if the user inputs the ? letter, I want to give him a message that this
character is not allowed and to delete this input for the field value.
I unsuccessfully coded the following, please assist

function CHAREF_onKey(nChar, nPosition,bShift,bCo
ntrol)
if nchar = 97
msgbox("The last entered character is not allowed!", "Message", 16)
endif
// return false
// return 0
I used return false and return 0 but still the character is not deleted
thanks
Moses


Moses Hanna

2005-11-08, 9:24 am

Sorry, the nchar should be 63 and not 97

"Moses Hanna" <mosesjhanna@hotmail.com> wrote in message
news:bdTdxu34FHA.1236@news-server...
> Hi
> I have a character field (charef)
> if the user inputs the ? letter, I want to give him a message that this
> character is not allowed and to delete this input for the field value.
> I unsuccessfully coded the following, please assist
>
> function CHAREF_onKey(nChar, nPosition,bShift,bCo
ntrol)
> if nchar = 97
> msgbox("The last entered character is not allowed!", "Message",
> 16)
> endif
> // return false
> // return 0
> I used return false and return 0 but still the character is not deleted
> thanks
> Moses
>



Ivar B. Jessen

2005-11-08, 9:24 am

On Mon, 7 Nov 2005 20:08:41 +1100, "Moses Hanna" <mosesjhanna@hotmail.com>
wrote:

>Hi
>I have a character field (charef)
>if the user inputs the ? letter, I want to give him a message that this
>character is not allowed and to delete this input for the field value.
>I unsuccessfully coded the following, please assist
>
> function CHAREF_onKey(nChar, nPosition,bShift,bCo
ntrol)
> if nchar = 97
> msgbox("The last entered character is not allowed!", "Message", 16)
> endif
>// return false
>// return 0
>I used return false and return 0 but still the character is not deleted



Use the Key event, not the onKey event.

function ENTRYFIELD1_key(nCha
r, nPosition,bShift,bCo
ntrol)
if nchar = 63
msgbox("The last entered character is not allowed!", "Message", 16)
retVal = false
else
retval = true
endif
return retVal


Ivar B. Jessen
John Jay

2005-11-08, 9:24 am

Moses

> I have a character field (charef)
> if the user inputs the ? letter, I want to give him a message that this
> character is not allowed and to delete this input for the field value.


I do it this way in the char fields with a length of 1 in the
onlostfocus event
if this.value $ "?><" and msgbox(this.value+" is not allowed in this
field","Imput Error",;
0)=1 // combine the 2 msgbox will always return 1 in this case
this.value=" "
form.thisfield.setfocus()
endif
I used $ because you can test for all unwanted single letter entries.
If the field length is longer than 1 try
if at("?",this.value)>0 and msgbox(this.value+" is not allowed in this
field","Imput Error",;
0)=1 // combine the 2, msgbox will always return 1 in this case
this.value=space(this.entryfield.length)
* or to retain previous imput
this.value=substr(this.value,1,
at("?",this.value)-1+space(this.field.length-at("?",this.value)-1)
form.thisfield.setfocus()
endif
To test for more that 1 unallowed entry anywhere in the field I use a case
endcase construct.
John Jay
Best Marine


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com