USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Conversao mto Treta: DO DBF para TEXT
Mazarope
não registrado
Postada em 05/11/2004 14:19 hs   
Ola amigos.

Estou no servico apanhando muito para saber como fazer que um arquivo bdf se converta em txt. Jah esta tudo feito, o problema eh que ele esta repitindo os dados da tabela, nao esta passando para o proximo registro e fazendo tudo em uma linha só, aqui esta o codigo

    Set Conn = New ADODB.Connection
    SQLConn = "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=21;Dbq=" & Caminho
    Conn.Open SQLConn
    SQL = "SELECT * FROM " & Text2.text
    Set rsDarf = New ADODB.Recordset
    'rsDarf.CursorLocation = adUseServer
    rsDarf.CursorType = adOpenForwardOnly
    rsDarf.LockType = adLockOptimistic
    rsDarf.Open SQL, Conn, , , adCmdText
    vArqTexto = CurDir$ & "" & Text2.text & ".txt"
    Open vArqTexto For Output As #1
      
While Not rsDarf.EOF

        If Not IsNull(rsDarf.Fields("Telefone")) Then
            'vTexto = rsDarf.Fields("TeleFone") + ";" + Space(8)
        vTexto = vTexto + Left(rsDarf.Fields("Telefone") + Space(8), 10)
        rsDarf.MoveNext
        End If
        
        If IsNull(rsDarf.Fields("Telefone")) Then
            vTexto = Left(rsDarf.Fields("tenefone") + Space(8), 10)
        rsDarf.MoveNext
        End If
        
        If Not IsNull(rsDarf.Fields("Cidade")) Then
               vTexto = vTexto + Left(rsDarf.Fields("Cidade") + Space(30), 30)
        rsDarf.MoveNext
        End If
        
        If IsNull(rsDarf.Fields("cidade")) Then
               vTexto = vTexto + Left(rsDarf.Fields("Nome") + Space(30), 30)
        rsDarf.MoveNext
        End If
        
        If Not IsNull(rsDarf.Fields("Nome")) Then
            vTexto = vTexto + Left(rsDarf.Fields("Nome") + Space(20), 20)
        rsDarf.MoveNext
        End If
        
        If IsNull(rsDarf.Fields("Nome")) Then
            vTexto = vTexto + Left(rsDarf.Fields("Nome") + Space(20), 20)
        rsDarf.MoveNext
        End If
        
        If Not IsNull(rsDarf.Fields("Endereco")) Then
            'vTexto = vTexto + rsDarf.Fields("Endereco") + ";" + Space(60)
        vTexto = vTexto + Left(rsDarf.Fields("Endereco") + Space(60), 60)
        rsDarf.MoveNext
        End If
        
        If IsNull(rsDarf.Fields("Endereco")) Then
        vTexto = vTexto + Left(rsDarf.Fields("Endereco") + Space(60), 60)
        rsDarf.MoveNext
        End If
        
        If Not IsNull(rsDarf.Fields("CPF")) Then
            ''''vTexto = vTexto + rsDarf.Fields("CPF") + ";"
        vTexto = vTexto + Left(rsDarf.Fields("CPF") + Space(14), 14)
        rsDarf.MoveNext
        End If
        
        If IsNull(rsDarf.Fields("CPF")) Then
        vTexto = vTexto + Left(rsDarf.Fields("CPF") + Space(14), 14)
            ''''vTexto = vTexto + Left(rsDarf("CPF") + Space(14), 14)
        rsDarf.MoveNext
        End If
        
        If Not IsNull(rsDarf.Fields("CEP")) Then
            ''''vTexto = vTexto + rsDarf.Fields("CEP") + ";"
        vTexto = vTexto + Left(rsDarf.Fields("CEP") + Space(8), 8)
        rsDarf.MoveNext
        End If
        
        If IsNull(rsDarf.Fields("CEP")) Then
        vTexto = vTexto + Left(rsDarf.Fields("CEP") + Space(8), 8)
        ''''vTexto = vTexto + Left(rsDarf("Nome") + Space(60), 60)
        rsDarf.MoveNext
        End If
        
        If Not IsNull(rsDarf.Fields("Bairro")) Then
           ''''vTexto = vTexto + rsDarf.Fields("Bairro") + ";"
        vTexto = vTexto + Left(rsDarf.Fields("Bairro") + Space(20), 20)
        rsDarf.MoveNext
        End If
        
        If Not IsNull(rsDarf.Fields("DDD")) Then
            ''''vTexto = vTexto + rsDarf.Fields("DDD")
        vTexto = vTexto + Left(rsDarf.Fields("Nome") + Space(4), 4)
        rsDarf.MoveNext
        End If
        
        If IsNull(rsDarf.Fields("DDD")) Then
        vTexto = vTexto + Left(rsDarf.Fields("Nome") + Space(4), 4)
        rsDarf.MoveNext
        End If
        
        Print #1, vTexto
        vAtual = vAtual + 1
        vTotal = vTotal + 1
        Label1.Caption = "Lendo Registro " & Format(vAtual, "#########0") & " de " & Format(vTotal, "#########0")
        DoEvents
        rsDarf.MoveNext
    Wend



Abracos
     
Jose.Niz
CURITIBA
PR - BRASIL
Postada em 06/11/2004 17:41 hs         
Corrija os itens abaixo:
1) Retire rsDarf.MoveNext de todos os IFs. O MoveNext e para avançar um registro e não um campo !
2) Após a linha Print #1, vTexto inicialize a variável vTexto (vTexto = "").
3) Após o encerramento do laço While feche o recordset (rsDarf.Close) e o arquivo (Close #1).
     
Página(s): 1/1    


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2025   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página