Jump to content
Fivewin Brasil

importar dados separados por PIPE |


marcioe

Recommended Posts

Marcio

Boa noite

Qual a dúvida? Você pode ler com a classe de ler txt, dar um append from SDF para um DBF e ler os registros.

Ai você lê a string e vai comparando

dbcreate("temp.dbf",{{"campo","C",1000,00}})
use temp alias temp new shared
append from arq.txt sdf
tmp->( dbgotop() )
while tmp->(!Eof())
xi:=1
cTxt := ""
aVetor:={}
for xi:=1 To Len(Alltrim(tmp->campo))
      If substr(tmp->campo,xi,1) == "|"
           AADD( aVetor, cTxt )
           cTxt :=""
      Else       
           cTxt+=substr(tmp->campo,xi,1) 
      Endif
Next

? len(aVetor)
tmp->(DbSkip(1))
End

Neste exemplo você vai ter um vetor com os campos do arquivo em cada posição.

Att

João Bosco

Link to comment
Share on other sites

A Hb_ATokens funciona otimo para o que voce deseja junto com o ttxtfile

veja o ex:

oTxtFile = TTxtFile():New( "c:\caminho\arquivo.txt" ) // como abrir o arquivo

While oTxtFile:nLine<=oTxtFile:nTLines

sTexto:=oTxtFile:ReadLn() // Le a linha

aTexto:=Hb_ATokens (sTexto,"|")// cria o vetor

oTxtFile:Skip() // pula a linha para a proxima

end

assim ele vai andar em cada linha e te retornar um vetor com as posiçoes

referencias

http://www.freag.net/en/t/1cml3/hb_atokens

http://wiki.fivetechsoft.com/doku.php?id=fivewin_class_ttxtfile

Link to comment
Share on other sites

oFile:=cFile:=""

cFile := cGetFile( "*.txt", cFile )

if empty(cFile)

return(nil)

endif


if ! msgyesno("Confirma processamento do arquivo "+cFile,"ATENÇÃO")

return(nil)

endif


******** CANCELADOS

QUANTOS:=0

QUANTOS2:=0

VALOR:=0

cFile1:=cFile+"X"

oText := TTxtFile():New( cFile )

oText1=TTxtFile():New(cFile1)

oText1:Open()

cTotLinha:= oText:RecCount()+1

oMeter:SetRange(0,cTotLinha/100 )

oMeter:SetPos( 0 )

for n = 1 to cTotLinha

cLinha:= oText:ReadLine()

if substr(cLinha,1,17) ="|D100|1|0||57|02|"

zLinha:= StrToken( cLinha,9, "|" ) // irá pegar o nono campo da linha lida

oText1:Add(zLinha)

QUANTOS+=1

endif

oText:Skip()

QUANTOS2+=1

oMeter:SetPos( QUANTOS2/100 )

next

* oText:Close()

oTExt1:close()

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...