Subject Entering data
From Mervyn Bick <invalid@invalid.invalid>
Date Mon, 25 Oct 2021 10:33:33 +0200
Newsgroups dbase.getting-started
Attachment(s) enter_data.wfm

On 2021/10/25 03:18, Colin Wilson wrote in the bug-reports newsgroup:
> I recently downloaded a trial version of dBase 2012 but found that
>when entering data I HAD ti use the Tab key to move from field to
>field.  Is there anyway to get dBase to use the <enter> key the way it
>worked in dBase !! ,  III and V
> E.G
> 27 My Street<enter>
> Mytown<enter>
> Myzipcode<enter>
>
> And then because "Myzip" is the last field roll on to a new blank
record for the operator to enter more data.
>

I've move my reply here as the thread is not appropriate for the
bug-reports newsgroup.

As Ken has pointed out the default is for the CUAENTER property to be
set on. If you enter  SET CUAENTER OFF  in the Command Panel the setting
is only in force until you close dBASE.  If you change the setting in
the Desktop Properties dialogue box the setting is written to plus.ini
and is in force each time you open dBASE.

Setting CUAENTER OFF has other ramifications (See CUAENTER in the help
file) and it is better to leave it set ON.

Every programmer develops a personal style with personal preferences.
In my case I prefer to leave CUAENTER set ON.  On the (very rare)
occasions that I want it set off I set it off in my program and set it
back when I'm done.  If I have both hands on the keyboard I find it just
as convenient to press the Tab key as the Enter key.

There are various ways of programming what you want.  Twelve
programmers, a dozen solutions. :-)

If you are new to Object Oriented Programming you would do well to work
through the tutorial available from Ken's website at
http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm

For the attached example I've opted to use datalinked entryfields.  The
grid is not editable (I virtually never allow editing in a grid as it is
far to easy to make errors) and is there so that you can see "behind the
scenes".

Using datalinked entryfields means that the selected record in the
rowset is displayed in the entryfields.  As I consider this to be
"untidy" I disconnect the datalinks when the form opens and attach them
when data is to be entered.  This is my personal preference and you can
decide if you need this or not.


Mervyn.





if file('enter_data.dbf')
// drop table enter_data
endif

if not file('enter_data.dbf')
   create table enter_data  (id autoinc,street character(25),town character(25),;
     zip character(10))
endif
** END HEADER -- do not remove this line
//
// Generated on 2021-10-25
//
parameter bModal
local f
f = new enter_dataForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class enter_dataForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 16.0
      left = 34.0
      top = 0.1364
      width = 113.1429
      text = ""
   endwith

   this.ENTER_DATA1 = new QUERY(this)
   with (this.ENTER_DATA1)
      left = 3.0
      width = 9.0
      height = 1.0
      sql = 'select * from "enter_data.DBF"'
      active = true
   endwith

   this.ENTRYFIELDSTREET1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELDSTREET1)
      when = {||false}
      dataLink = form.enter_data1.rowset.fields["street"]
      height = 1.0
      left = 63.8571
      top = 9.1364
      width = 27.0
   endwith

   this.ENTRYFIELDTOWN1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELDTOWN1)
      when = {||false}
      dataLink = form.enter_data1.rowset.fields["town"]
      height = 1.0
      left = 63.8571
      top = 11.1818
      width = 27.0
   endwith

   this.ENTRYFIELDZIP1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELDZIP1)
      onKey = class::ENTRYFIELDZIP1_ONKEY
      when = {||false}
      dataLink = form.enter_data1.rowset.fields["zip"]
      height = 1.0
      left = 63.8571
      top = 13.3182
      width = 12.0
   endwith

   this.TEXTLABEL1 = new TEXTLABEL(this)
   with (this.TEXTLABEL1)
      height = 1.0
      left = 47.2857
      top = 9.1364
      width = 12.0
      text = "Street"
   endwith

   this.TEXTLABEL2 = new TEXTLABEL(this)
   with (this.TEXTLABEL2)
      height = 1.0
      left = 47.2857
      top = 11.3182
      width = 12.0
      text = "Town"
   endwith

   this.TEXTLABEL3 = new TEXTLABEL(this)
   with (this.TEXTLABEL3)
      height = 1.0
      left = 47.2857
      top = 13.5
      width = 12.0
      text = "Zipcode"
   endwith

   this.GRID1 = new GRID(this)
   with (this.GRID1)
      dataLink = form.enter_data1.rowset
      allowEditing = false
      height = 6.5
      left = 4.0
      top = 1.9091
      width = 105.8571
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.0909
      left = 12.2857
      top = 9.8636
      width = 15.2857
      text = "Start data entry"
   endwith

   this.PUSHBUTTON2 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON2)
      onClick = class::PUSHBUTTON2_ONCLICK
      height = 1.0909
      left = 12.0
      top = 12.8636
      width = 15.2857
      text = "End data entry"
   endwith

   this.rowset = this.enter_data1.rowset

   function ENTRYFIELDZIP1_onKey(nChar, nPosition,bShift,bControl)
      if nChar = 9
     //With cuaenter OFF pressing the enter key returns 9 instead of 13
         form.enter_data1.rowset.save()
         form.enter_data1.rowset.beginAppend()
         form.entryfieldstreet1.setFocus()
      endif  
      return

   function PUSHBUTTON1_onClick()
      set cuaenter off //Enter key act as Tab.
      form.enter_data1.rowset.beginAppend() //Add new blank record
      form.entryfieldstreet1.when = {||true} //Allow entryfeld to accept focus
      form.entryfieldtown1.when = {||true}
      form.entryfieldzip1.when = {||true}
      //Set entryfield daalink properties
      form.entryfieldstreet1.datalink = form.enter_data1.rowset.fields["street"]
      form.entryfieldtown1.datalink = form.enter_data1.rowset.fields["town"]
      form.entryfieldzip1.datalink = form.enter_data1.rowset.fields["zip"]
      form.entryfieldstreet1.setFocus()
      return

   function PUSHBUTTON2_onClick()
      set cuaenter on //Enter key does not act as tab
      form.entryfieldstreet1.when = {||false} //Don't allow entryfeld to accept focus
      form.entryfieldtown1.when = {||false}
      form.entryfieldzip1.when = {||false}
      //Disconnect entryfield datalinks
      form.entryfieldstreet1.datalink = ''
      form.entryfieldtown1.datalink = ''
      form.entryfieldzip1.datalink = ''
      if empty(form.entryfieldstreet1.value) ;
         or empty(form.entryfieldtown1.value) ;
         or empty(form.entryfieldzip1.value)  // Incomplete or empty record
         form.enter_data1.rowset.abandon()  //Delete unused blank record
      endif  
      return

   function form_onOpen()
      //Disconnect entryfield datalinks so that entryfields are blank
      //when the form opens.
      form.entryfieldstreet1.datalink = ''
      form.entryfieldtown1.datalink = ''
      form.entryfieldzip1.datalink = ''
      return

endclass