KB-12658: Como ler/escrever em arquivos texto (TXT)
pelo E3. Descrição:
Como ler/escrever em arquivos TXT a partir do E3?
Solução:
Para isto, deve-se utilizar os métodos do objeto FileSystemObject.
Exemplos:
** Script para criar arquivo txt **
Dim aux, aux1
Set aux = CreateObject("Scripting.FileSystemObject")
Set aux1 = aux.CreateTextFile("C:\Temp\Teste.txt", True) aux1.Close
** Script para adicionar texto no arquivo **
Dim aux, aux1
Set aux = CreateObject("Scripting.FileSystemObject")
Set aux1 = aux.OpenTextFile("C:\Temp\Teste.txt",8) aux1.WriteLine " Adiciona texto ao arquivo " aux1.Close
** Script para apagar conteúdo do arquivo **
Dim aux, aux1
Set aux = CreateObject("Scripting.FileSystemObject")
Set aux1 = aux.OpenTextFile("C:\Temp\Teste.txt",2) aux1.Write " " aux1.Close
** Script para deletar arquivo texto **
Dim aux
Set aux = CreateObject("Scripting.FileSystemObject")
aux.DeleteFile("C:\Temp\Teste.txt") ** Script para ler o conteúdo do arquivo TXT e carregar para dentro da tag Interna 1 **
Const ForReading = 1, ForWriting = 2
Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("C:\TEMP\Teste.txt", ForReading) Application.GetObject("Dados.TagInterno1").Value = f.ReadAll
Observação: Anexo a este artigo está uma aplicação exemplo com os métodos descritos acima.