Subject Re: Print Entryfield Editor
From Mervyn Bick <invalid@invalid.invalid>
Date Wed, 27 Apr 2022 11:51:22 +0200
Newsgroups dbase.getting-started
Attachment(s) employees.wfm

On 2022/04/26 05:34, Norman Snowden wrote:

> I hesitate to bring p this additional question about the Editor. My program includes rowsets of people I know. I copied an Array of those that are Checkboxed relatives and used the Editor to calculate "Last", "first", names "birthday",etc. of those particular people. It runs fine and an option will also print the results. However, the name of the generated text.file  becomes embedded into the dbf Table field "Last" name. After returning to the home page the last name identify has been replaced with the text.file name. The same result occurs when beginning from any highlighted persons
> name on the Home page. Oddly, the names shown in the ListBox which is also on the Home page show correctively. The Editor code I used is shown in my original Post.
>
> This is not critical as I am a hobby programmer. Even so, any comment would be appreciated. Thanks, Norman
>

Don't ever hesitate to ask if you have a problem.  There is no limit to
the number of questions anyone may ask and there is no such thing as a
"silly" question.

There is nothing in the pushbutton11 onClick event handler which could
write back to the .dbf file.  As you didn't give us all the code which
creates the array it is not possible to pinpoint the problem.  Somewhere
in there is a line which assigns the file name to the "last" field.  If
you can't find it post all the code that creates the array so that fresh
eyes can look at it for you.

Unless you really need the array you can create the list in the editor
direct from the .dbf file.  A little example is attached.

The example uses a table from the DBASESAMPLES database so the choice of
indexes is relevant to the table.

If you need make a list of relatives from your table you could use an
index and the rowset's setRange() method.  You would need an index on
the relative field in your table.  Because this is a logical field it
needs to be presented as a character for the index.

   use yourtable exclusive
   index on iif(relative = true,'t','f') tag relative
   use

Note, you can't use 'true' or 'false' in the index expression as the
index values for all records must be the same length.

If you want the names in alphabetical order

   index on iif(relative = true,'t','f')+last tag relative_last

To include just the relatives in your list

    form.queryname.rowset.indexname = 'relative_last'
    form.queryname.rowset.setRange('t')

To return to an ordered list of all names with non-relatives followed by
relatives

    form.queryname.rowset.clearRange()

To return to the unordered list

    form.queryname.rowset.indexname = ''



The table's MDX file can hold up to 47 indexes so you should be able to
create an index for any situation.


Mervyn.


** END HEADER -- do not remove this line
//
// Generated on 2022-04-27
//
parameter bModal
local f
f = new employeesForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class employeesForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 22.0455
      left = 47.2857
      top = 0.3182
      width = 62.5714
      text = ""
   endwith

   this.DBASESAMPLES1 = new DATABASE(this)
   with (this.DBASESAMPLES1)
      left = 14.0
      width = 11.0
      height = 1.0
      databaseName = "DBASESAMPLES"
      active = true
   endwith

   this.EMPLOYEES1 = new QUERY(this)
   with (this.EMPLOYEES1)
      left = 4.0
      width = 8.0
      height = 1.0
      database = form.dbasesamples1
      sql = "select * from EMPLOYEES.DBF"
      active = true
   endwith

   this.EDITOR1 = new EDITOR(this)
   with (this.EDITOR1)
      height = 14.3636
      left = 7.5714
      top = 1.6364
      width = 46.0
      value = ""
      fontName = "Consolas"
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      height = 1.0
      left = 33.2857
      top = 18.0455
      width = 15.7143
      value = "employees.txt"
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.0909
      left = 39.8571
      top = 19.9545
      width = 15.2857
      text = "Print using Word"
   endwith

   this.PUSHBUTTON2 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON2)
      onClick = class::PUSHBUTTON2_ONCLICK
      height = 1.0909
      left = 2.7143
      top = 19.9545
      width = 15.2857
      text = "Create list"
   endwith

   this.TEXTLABEL1 = new TEXTLABEL(this)
   with (this.TEXTLABEL1)
      height = 1.0
      left = 33.8571
      top = 16.7273
      width = 12.0
      text = "File name"
   endwith

   this.COMBOBOX1 = new COMBOBOX(this)
   with (this.COMBOBOX1)
      onChange = class::COMBOBOX1_ONCHANGE
      height = 1.0
      left = 14.8571
      top = 18.0455
      width = 15.2857
      style = 1        // DropDown
   endwith

   this.TEXTLABEL2 = new TEXTLABEL(this)
   with (this.TEXTLABEL2)
      height = 1.0
      left = 18.8571
      top = 16.7273
      width = 12.0
      text = "Order by"
   endwith

   this.rowset = this.employees1.rowset

   function COMBOBOX1_onChange()
      if this.value = 'No Index'
         form.employees1.rowset.indexname = ''
      else  
         form.employees1.rowset.indexname = this.value
      endif  
      return

   function PUSHBUTTON1_onClick()
      cFile = set('directory')+'\'+form.entryfield1.value
      oWord = new oleAutoclient("word.application")
      oWord.documents.open(cFile,false,true)
      oWord.activeDocument.printOut()
      oWord.quit( 0 )
      release object oWord
      oWord = null
      return

   function PUSHBUTTON2_onClick()
      crlf = chr(13)+chr(10)
      if empty(form.entryfield1.value)
         msgbox('File name required','Error')
         return
      else
         f = new file()
         f.create(form.entryfield1.value)
      endif
      //reset the row pointer and empty editor display
      //Not needed for first list but required if the index is changed for a new list
      form.employees1.rowset.first()
      form.editor1.value = ''      
      ferf = form.employees1.rowset.fields  //"shortcut" to save typing in the loop
      do while not form.employees1.rowset.endofset
         cStr =  trim(ferf['firstname'].value)+' '+trim(ferf['lastname'].value)
         cstr += space(25-len(cstr))
         cStr += ferf['hiredate'].value
         f.puts(cStr)
         form.editor1.value += cStr+crlf
         form.employees1.rowset.next()
      enddo
      f.close()
      return

   function form_onOpen()
      //tableDef object has an array contining the available index names
      t=new TableDef()
      t.tableName=form.employees1.rowset.tablename
      t.load()
      //create new array with 'No Index' option
      form.indexNames = new array()
      form.indexNames.add('No Index')
      //add the indexes available
      for n = 1 to t.indexes.size
         form.indexNames.add(t.indexes[n].indexname)
      next
      //assign new array to combobox's datasource
      form.combobox1.datasource = 'array form.indexNames'
      return

endclass