


proc grava(s)
 FileWrite Append arqtxt From s+"\n"
Endproc


Proc gravacampo()

Switch
  case nf="": 
       tm1=len(s)
       tm2=len(ltrim(s))

       If tm2=0 
          then Return
       endif
         
       nc=nc+(tm1-tm2)
       tm=tm-(tm1-tm2)
       s=ltrim(s)
       
       Switch
         case s="ate "                   : s="at"+chr(130)+" "       
         case s="Emissao: "              : s="Emiss„o: "       
       EndSwitch
       
  otherwise: 
       if subStr(nf,1,1)="["
          Then If searchfrom("[",nf,2)=0
                  Then nf=xtrim(nf,"[]")
               EndIf
       Endif

       if not isfield(nf)
          then Switch
                 case nf="NOMEMPRESA"                        : tpf="varprg" 
                 case substr(nf,1,3)="CI_"                   : tpf="varprg" 
                 case substr(nf,1,4)="VSDG"                  : tpf="varprg" 
                 case nf="Current time"                      : tpf="varrpt" 
                 case nf="Current page number"               : tpf="varrpt"
                 case nf="Format(\"D13\",Today())"           : tpf="varrpt" nf="today()"
                 case nf="Format(\"D13\",VSDGDTINI)"         : tpf="varprg" nf="VSDGDTINI" s="DD/MM/AAAA"
                 case nf="Format(\"D13\",VSDGDTFIM)"         : tpf="varprg" nf="VSDGDTFIM" s="DD/MM/AAAA"
                 case search("FORMAT",upper(nf))>0           : tpf="calculado"

                 case search("TOTAL FOR ",upper(nf))>0       : 
                      nf=substr(nf,10,Len(nf))
                      pos=search(",",nf)
                      tpf="sum"+substr(nf,pos,30)
                      nf=substr(nf,1,pos-1)
                 otherwise                                   : tpf="varprg" 
               EndSwitch
      endif

EndSwitch


If s<>"" then s="\""+s+"\"" endif

Grava(AlinhM(StrVal(nlb),2)+","+AlinhM(StrVal(nc),3) +"|"+ Completa(tpf,20," ") +"|"+ Completa(nf,80," ") +"|"+ Completa(tf,07," ") +"|" +Alinhm(strval(tm),3) +"|" +s)

Endproc


proc isfield(campo)
private i

for i from 1 to NFields(Tabela)
  if upper(array_campos[i])=upper(campo)
     then tf=array_tipos[i]
          switch
            case substr(tf,1,1)="A"  : tf="texto"
            case substr(tf,1,1)="M"  : tf="memo"
            case tf            ="N"  : tf="decimal"
            case tf            ="S"  : tf="inteiro"
            case tf            ="$"  : tf="moeda"
            case tf            ="D"  : tf="data"
          endswitch
          tpf="field"
          return true
  endif   
endfor 
return false
endproc

;;;Rotina principal
AutoLib="\\Sistemas\\Cadastro\\Bibliot,\\Sistemas\\Cadastro\\Bib_Show"

setdir "\\sistemas\\vendas"
tabela="\\sistemas\\vendas\\rm_3100"

{Report} {Change} 

typeIn tabela enter 
;rpt=menuchoice()
rpt="?"
{R}
titrpt=menuchoice() Enter

TableInfo Tabela Fields to Array_campos, Array_tipos

arqtxt="\\sistemas\\cadastro\\testrpt.txt"

FileWrite arqtxt From ""

{setting} {pagelayout} {length} 
pl=menuchoice()
enter

pw=pagewidth()

Grava("tabela    ="+tabela)
Grava("report    ="+rpt)
Grava("nome      ="+titrpt)
Grava("pagewidth ="+strval(pw))
Grava("pagelength="+strval(pl))

nband=""
While True

  nl =rowno()

  If BandInfo()<>nband
     Then nband=BandInfo()
          Grava("")
          Grava("* "+nband)
          nlb=0
  EndIf   

  t=cursorline()
  If Search(Chr(196),t)=0 And
     (Search(Chr(30),t)=0 or Search(Chr(31),t)=0)
     Then    
          Grava("")

          nlb=nlb+1
          
          nf="?"
          For i From 1 To pw
        
           If FieldInfo()<>nf
              Then 
                   If i>1 Then GravaCampo() EndIf
   
                   s=""
                   nf =FieldInfo()
                   tpf="caption"
                   tf =""   
                   tm =0
                   nc =i
 
           Endif
           s=s+cursorchar()
        
           tm=tm+1
        
           Right
           
          EndFor
          
          Switch
            Case nf="": 
                 If STrim(s)<>"" 
                    Then s=rtrim(s)
                         tm=len(s)
                         GravaCampo() 
                 EndIf
            OtherWise : 
                 
                 
                 GravaCampo()
          EndSwitch   

  EndIf


  CtrlHome
  Down
  
  If rowno()=nl then quitLoop endif
EndWhile


Do_It!
setdir "\\sistemas\\cadastro"


ClearAll
Release Vars All
Release Procs All
 
