Subject Re: Editor Problem
From Norman Snowden <duluth@msn.com>
Date Tue, 09 Jul 2024 15:03:00 -0400
Newsgroups dbase.getting-started

Norman Snowden Wrote:

> Mervyn Bick Wrote:
>
> > 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.
> >
> > Mervyn, Thanks for your new valuable code. My following comments are for information only. You have already done enough . I don't expect any more response.
> When I ran your code I got the Error message: " Expecting Character for the Lines rm.editor1.value += '        ' + D + '    '+LTRIM(E)
> >      form.editor1.value += '            '+ LTRIM(F)+ '      ' + G
> Rather than trying to find the answer to this minor error, I opened this successful program on my Laptop. For some dumb reason, I clicked Print when there is no Printer connected. This caused the Program to only Flash and close when Clicking on Print. Back on the Laptop  when I Clicked Print I got the message: Error: In use by another :Plot-Relatives.txt, Line 1703, fFile.create('plot_Relatives.txt'). Additionally, when I open the program, the Entries for Lname, appear as: C:\mykinda|plot Rle. The  function PUSHBUTTON10_onClick()
>     ***************
>               Chooseprinter()
>                         Set Printer On                      
>                 cFile = set('directory')+'\plot_relatives.txt' // From Murvyn 04/23/22
>         oWord = new oleAutoclient("word.application")
> //      oWord.ChangeFileOpenDirectory( set('directory')+'\')
>        oWord.documents.open(cFile,false,true)
>        oWord.activeDocument.printOut()
>        oWord.quit( 0 )
>        release object oWord
>        oWord = null
>      return,,  provides the basis for Printing. This is beyond my dBase knowledge. The Microsoft Word communication must come from the Word in my computer. Again, when I run the Program The message comes up: In use by another. For now I will just use a List or Display Command that shows all the People rather than a separate Relative list. Mervyn, Thanks for your patience and help for many years, Norman  

XXXXXXXXXXXXXXXXXXXXXX
Wow! I must be getting memory problems! (I am 94 years old) I apologize for not using SEARCH for my past questions and earlier dBase answers! Norman