Subject Re: Entryfield does not recognise the Enter Key
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Thu, 26 Jan 2023 18:18:01 +0530
Newsgroups dbase.getting-started
Attachment(s) test_cua.wfm

Good Evening Micahel,

>
> I have an unusual problem. I have an entryfield that for some reason wont recognise the enter key.
>
> If CUAENTER is off then pressing enter jumps to the next field. In either case enter is not recognised in the nchar value of the entryfield key method.
>
> It use to be, i use it when reading barcodes then searching a database. once it hit the chr(13) character it would automatically oclick a pushbutton that would then search the database.
>
> For example
>
>     function ENTRYFIELD1_key(nChar, nPosition,bShift,bControl)
>
>         If nChar = 13
>                     FORM.PUSHBUTTON1.ONCLICK()                
>         ENDIF        
>
>        return
>
> However for the life of me it simply wont pick up the nChar value when it used to or am i missing something?
>
> Anyone have this problem in the past?

I use the barcode reader (None of my bar code readers add a carriage
return or any other character they just return the bar code or qr code).
I set the value of CUAENTER once so that pressing enter moves the
control to the next field in the Z order.

Now the question arises how to check for bar code completion.

I check the length of entryfield value.

    function EAN_CODE_EF_onKey(nChar, nPosition,bShift,bControl)
       if len(alltrim(this.value)) = 13

So if the length is what it is supposed to be then proceed else ignore.

You will have to change the settings in bar code reader if you want the
bar code reader to return carriage return or not.

As an alternative if you want different cuaenter values for different
entryfields try the attached form. In the first field Pressing enter
will just display 13 in results pane.

In second entryfield pressing enter will shift control to first entryfield.

Regards
Akshat


** END HEADER -- do not remove this line
//
// Generated on 26-01-2023
//
parameter bModal
local f
f = new test_cuaForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class test_cuaForm of FORM
   with (this)
      height = 16.0
      left = 69.1429
      top = 0.0
      width = 63.4286
      text = ""
      clientEdge = true
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      onGotFocus = class::ENTRYFIELD1_ONGOTFOCUS
      onLostFocus = class::ENTRYFIELD1_ONLOSTFOCUS
      onKey = class::ENTRYFIELD1_ONKEY
      height = 1.0
      left = 9.0
      top = 4.0
      width = 8.0
      value = "Entryfield1"
   endwith

   this.ENTRYFIELD2 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD2)
      height = 1.0
      left = 9.0
      top = 7.0
      width = 8.0
      value = "Entryfield2"
   endwith


   function ENTRYFIELD1_onGotFocus()
      set cuaenter on
      return

   function ENTRYFIELD1_onKey(nChar, nPosition,bShift,bControl)
      ?nChar
      return

   function ENTRYFIELD1_onLostFocus()
      set cuaenter off
      return

endclass