Subject Re: Editor Problem
From Mervyn Bick <invalid@invalid.invalid>
Date Mon, 8 Jul 2024 14:06:46 +0200
Newsgroups dbase.getting-started

On 2024/07/07 20:18, Norman Snowden wrote:
> Mervyn provided this code for me a couple of years ago. It worked beautifully. It still works on my Laptop. I recently did some adjustments on the program working with my Desk Top. Now when I run it on the Desk Top the screen just flashes the program title and closes. I don't think I altered any of this code. Thanks, Mervyn for your help over the years. I think this was associated with Note Pad. Any ideas? PUSHBUTTON9_onClick()
>     Go Top
>          Clear        
........
>   I would appreciate it if you think the code still looks correct.

<soapbox>
Lesson 1.  Always make backup copies and save them in a different place.
  A copy on the laptop is as good a place as any. :-)

Lesson 2.  NEVER make changes to a form (program, whatever UNLESS you
have a copy of the of the original backed up so that you can easily
revert to the original and start again.
</soapbox>

Trying to debug altered code without being able to run it is like
looking for a needle in a haystack and there is no guarantee that one
won't miss a typo.

The word function is missing before PUSHBUTTON9_onClick() but I assume
this was simply an error in copying the code into the clipboard.  You
have a field named lascontact.  Is this correct?

Instead of trying to find errors, I've tidied up the code and, with a
bit of luck, the errors have gone. :-)  Unfortunately the code is
untested as I don't have your table so it may still require work.

When it comes to adding lines to the bottom of the text already in an
editor on a form and also saving the results to a file line by line life
gets a bit complicated.  The editor control needs crlf after each line.
The file object's puts() or writeln() method adds it's own crlf as each
line is written.

It will make life (the code :-) ) much simpler if you build the string
in the editor including crlf after each line.  Once all appropriate
records have been dealt with use the file object's write() method to
create the output file in one fell swoop.  All those crlf's in the
editor's value property will be included without any hassles.

     fFile.write(form.editor1.value,len(form.editor1.value))
     fFile.close()

I've added the crlf as a separate operation instead of adding it to each
line of data as it is easy to miss on long lines.

Building the long lines of data has been split into sections so as to
make it easier if spaces need to be added or removed.

I've changed the DO WHILE ... ENDDO loop to a FOR ... NEXT loop.
Slightly simpler code where one knows exactly how many iterations are
required as one doesn't have to manually increment the counter.

Where k = 1, Relt[rle-(rle-k),1] evaluates to Relt[1,1] so you may just
as well use Relt[k,1] in your code.  This is true whether you use DO
WHEN...ENDDO or FOR...NEXT.


******* Revised code **********
//Watch for line wrap in Copy to Array line after it has
//been copied and pasted into your form

function PUSHBUTTON9_onClick()
   Go Top
   Clear  //This clears the result panel.  Not really needed here as ?
          //print command is not used in this code
   Count for relative = true to Rle         
   if Rle = 0
      verdict = msgbox("There are no Relatives Listed")
      return
   endif
   Declare Relt[rle,8]
   Copy to Array Relt fields Lname, Fname, Mi, city, state, phone,
birthday, lascontact For relative = true
   Asort(Relt)
   fFile = new file()
   fFile.create('plot_Relatives.txt')
   crlf = chr(13)+chr(10)
   form.editor1.value += space(84)+"RELATIVES"
   form.editor1.value += crlf
   form.editor1.value +=  "   LAST NAME"+ "                 " + "FIRST"
   form.editor1.value += "        "+ "INITIAL"+ "         " +"CITY"
   form.editor1.value += "                           "+ "STATE"
   form.editor1.value += "         "+ "PHONE"+"        "+" BIRTHDAY"
   form.editor1.value += "         "+"LAST CONTACT"
   form.editor1.value += crlf
   form.editor1.value += " "+replicate("_",104)+" "
   form.editor1.value += crlf
   for k = 1 to rle
     A = Relt[k,1]
     if A = "     "
       A = "   ?   "
     endif
     B = Relt[k,2]
     if B = "     "
        B = "   ?   "
     endif        
     C = Relt[k,3]
     if C = "     "
        C = "   ?   "
     endif                        
     D = Relt[k,4]
     if D = "     "        
        D = "  ?   "
     endif
     E = Relt[k,5]
     if E = "     "        
        E = "    ?   "
     endif
     F = Relt[k,6]
     if F = "     "        
        F = "    ?   "
     endif                                        
     G = Relt[k,7]
     if G = null  &&"     "        
        G = " 00/00/0000   "
     endif        
     H = Relt[k,8]
     if H = null  && "     "        
        H = "00/00/0000"   &&" 00/00/0000   ?   "
     endif
     form.editor1.value += ' ' + A + '      ' +B + '      '+ C
     form.editor1.value += '        ' + D + '    '+LTRIM(E)
     form.editor1.value += '            '+ LTRIM(F)+ '      ' + G
     form.editor1.value += '      ' + H
     form.editor1.value += crlf
   next
   fFile.write(form.editor1.value,len(form.editor1.value))
   fFile.close()
   form.entryfield1.value = set('directory')+'\Plot_Relatives.txt'
   form.Pageno = 3
   return
***********************************

Mervyn.