Creating a prn file from data base not working?

Creating a prn file from data base not working?

Postby hag » Fri Aug 08, 2008 4:58 am

2 items:

1. Using fwrite() to create a prn file.
The file is then picked up in excel. THe file is created but no data in it. 0 bits. Worked fine in 16 bit not working at all now. Any help is welcome.
Code below.

2. I tried the using oBrw:toexcel() and it worked pretty good however it entered the last line of the browse 600 times. Once for each record.

Help here would be great.


Code: Select all  Expand view  RUN
   ftitle := fieldname(2)
   fty13  := fieldname(55)
   fty1   := fieldname(43)
   fty2   := fieldname(44)
   fty3   := fieldname(45)
   fty4   := fieldname(46)
   fty5   := fieldname(47)
   fty6   := fieldname(48)
   fty7   := fieldname(49)
   fty8   := fieldname(50)
   fty9   := fieldname(51)
   fty10  := fieldname(52)
   fty11  := fieldname(53)
   fty12  := fieldname(54)
   faa14   := Fieldname(82)

   go top
   plfile := "pl"+substr(gld,5,2)+".prn"

   fcreate(plfile, FC_NORMAL)  // create a new file
   nHandle := fopen(plfile, FO_READWRITE)

   go top      
   fwrite(nHandle,upper(mcompname)+CRLF+CRLF)

   fwrite(nHandle, "Account" + space(30) + "Total"    + space(10) +;
   m1  + space(10) + ;
   m2  + space(10) + ;
   m3  + space(10) + ;
   m4  + space(10) + ;
   m5  + space(10) + ;
   m6  + space(10) + ;
   m7  + space(10) + ;
   m8  + space(10) + ;
   m9  + space(10) + ;
   m10 + space(10) + ;
   m11 + space(10) + ;
   m12 + space(10) + ;
   "%" + CRLF)   


   do while .not. eof() 

      down := down + 1

      if title = "==============================" .OR. title = "------------------------------" 

         fwrite(nHandle,space(30))
         fwrite(nhandle,SPACE(5) + trans(&fty13,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty1 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty2 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty3 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty4 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty5 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty6 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty7 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty8 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty9 ,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty10,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty11,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&fty12,repli("_",11)))
         fwrite(nHaNdle,SPACE(2) + trans(&faa14,repli("_",9)+ CRLF ))

         skip

      elseif !EOF()
         fwrite(nHandle, &ftitle)
         fwrite(nhandle, SPACE(2) + trans(&fty13, "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty1,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty2,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty3,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty4,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty5,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty6,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty7,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty8,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty9,  "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty10, "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty11, "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&fty12, "999,999,999") )
         fwrite(nHaNdle, SPACE(2) + trans(&faa14, "999,999.99") + CRLF )
         skip
      endif
   enddo

   fclose(nhandle)

   return nil

   // end function plascii()

Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Postby Antonio Linares » Fri Aug 08, 2008 6:43 am

Harvey,

1. Once FCreate() is called it automatically returns the file handle, so there is no need to open it again. Please try this example:

Code: Select all  Expand view  RUN
#include "FiveWin.ch"
#include "FileIO.ch"

function Main()

   local nHandle := FCreate( "test.txt", FC_NORMAL )

   FWrite( nHandle, "this" + CRLF )
   FWrite( nHandle, "is a" + CRLF )
   FWrite( nHandle, "test" + CRLF )

   FClose( nHandle )
   
   MsgInfo( MemoRead( "test.txt" ) )

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Fri Aug 08, 2008 6:52 am

Harvey,

2. Please show us how you are creating the xbrowse, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42111
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby hag » Fri Aug 08, 2008 6:14 pm

Antonio:

Info worked fine. Thanks.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 62 guests