Problemas na criação de TXT

4 views
Skip to first unread message

Ricky Bizarria

unread,
Oct 15, 2009, 7:51:33 AM10/15/09
to VB6 Brasil
Amigos, estou com um problema, na minha rotina pra criar um arquivo
texto, quando mando gerar um arquivo, ele até gera...mas depois de
gerado ele cria varios arquivos em branco, alguem ja viu isso...
Eu gostaria de saber se posso criar uma rotina para deletar essses
arquivos...dar um kill em tudo que tiver okb...
Valeu!

Gustavo Almeida

unread,
Oct 15, 2009, 8:05:20 AM10/15/09
to vb6b...@googlegroups.com
Se ele cria vários arquivos, é porque em algum lugar do seu código você está mandando criar esses arquivos...
 
Posta aqui o seu código, pra gente poder dar uma olhada...

Ricky Bizarria

unread,
Oct 15, 2009, 8:22:16 AM10/15/09
to VB6 Brasil
CmdSQL = "SELECT"
CmdSQL = CmdSQL & " RTRIM(CONVERT(VARCHAR(9),NUM_BOLETO_COBRANCA))
NUM_BOLETO_COBRANCA,"
CmdSQL = CmdSQL & " A.COD_FORNEC,"
CmdSQL = CmdSQL & " A.NUM_TITULO,"
CmdSQL = CmdSQL & " A.TIP_PAGTO,"
CmdSQL = CmdSQL & " A.NUM_BORDERO,"
CmdSQL = CmdSQL & " A.NOM_FORNEC,"
CmdSQL = CmdSQL & " A.STATUS,"
CmdSQL = CmdSQL & " A.TIP_COD_FORNEC,"
CmdSQL = CmdSQL & " A.NUM_FATURA,"
CmdSQL = CmdSQL & " A.DTA_EMISSAO_TITULO,"
CmdSQL = CmdSQL & " A.DTA_VCTO_TITULO,"
CmdSQL = CmdSQL & " A.VAL_TITULO,"
CmdSQL = CmdSQL & " A.VAL_DESCONTO_TITULO,"
CmdSQL = CmdSQL & " A.VAL_LIQUIDO_TITULO,"
CmdSQL = CmdSQL & " A.VAL_ACRESCIMO_TITULO,"
CmdSQL = CmdSQL & " A.ANO_FATURA,"
CmdSQL = CmdSQL & " B.COD_MOEDA,"
CmdSQL = CmdSQL & " B.num_dig_boleto,"
CmdSQL = CmdSQL & " A.NUM_BANCO_FORNEC,"
CmdSQL = CmdSQL & " A.NUM_AGENCIA_FORNEC,"
CmdSQL = CmdSQL & " A.NUM_DIG_AGENCIA_FORNEC,"
CmdSQL = CmdSQL & " A.NUM_CCORRENTE_FORNEC,"
CmdSQL = CmdSQL & " A.Num_Dig_CCorrente_Fornec,"
CmdSQL = CmdSQL & " A.SEQLAN,"
CmdSQL = CmdSQL & " A.NUM_REFERENCIA,"
CmdSQL = CmdSQL & " A.NOM_FORNEC,"
CmdSQL = CmdSQL & " A.NOM_BANCO_FORNEC,"
CmdSQL = CmdSQL & " A.TEL_FORNEC,"
CmdSQL = CmdSQL & " A.SWIFT_FORNEC,"
CmdSQL = CmdSQL & " A.CIDADE_FORNEC,"
CmdSQL = CmdSQL & " A.REGION_FORNEC,"
'Alteração feita por Henrique Bizarria em 17/09/2009, inclusão do
IFA_NUMBER
CmdSQL = CmdSQL & " A.IFA_NUMBER,"
CmdSQL = CmdSQL & " A.END_FORNEC,"
CmdSQL = CmdSQL & " A.CEP_FORNEC,"
CmdSQL = CmdSQL & " B.INF_COMP_BOLETO,"
CmdSQL = CmdSQL & " B.VAL_BOLETO,"
CmdSQL = CmdSQL & " B.NUM_BANCO_BOLETO,"
CmdSQL = CmdSQL & " B.NUM_CCORRENTE_BOLETO,"
CmdSQL = CmdSQL & " B.NUM_AGENCIA_BOLETO,"
CmdSQL = CmdSQL & " B.NUM_BASE_BANCO_BOLETO,"
CmdSQL = CmdSQL & " B.Num_Sufix_Banco_Boleto,"
CmdSQL = CmdSQL & " B.Ano_Boleto,"
CmdSQL = CmdSQL & " B.Dta_vcto_codbarras,"
CmdSQL = CmdSQL & " C.COD_EMPRESA,"
CmdSQL = CmdSQL & " C.COD_BANCO,"
CmdSQL = CmdSQL & " C.COD_AGENCIA,"
CmdSQL = CmdSQL & " C.NUM_CONTA,"
CmdSQL = CmdSQL & " C.NOM_BANCO,"
CmdSQL = CmdSQL & " C.CID_BANCO,"
CmdSQL = CmdSQL & " C.PAIS_BANCO,"
CmdSQL = CmdSQL & " Case B.Cod_Moeda"
CmdSQL = CmdSQL & " WHEN 9 THEN 'REAL'"
CmdSQL = CmdSQL & " Else 'OUTROS'"
CmdSQL = CmdSQL & " END AS NOM_MOEDA,"
CmdSQL = CmdSQL & " D.NOM_EMPRESA"

CmdSQL = CmdSQL & " From"
CmdSQL = CmdSQL & " Titulos_Pagar A,"
CmdSQL = CmdSQL & " Boletos_Pagar B,"
CmdSQL = CmdSQL & " EMPRESA_CONTA C,"
CmdSQL = CmdSQL & " Empresa D"

CmdSQL = CmdSQL & " Where"
CmdSQL = CmdSQL & " A.Empresa *= B.Cod_Empresa"
CmdSQL = CmdSQL & " and A.COD_FORNEC *= B.COD_FORNEC_BOLETO"
CmdSQL = CmdSQL & " AND A.NUM_TITULO *= B.NUM_TITULO_BOLETO"
CmdSQL = CmdSQL & " AND A.EMPRESA *=C.COD_EMPRESA"
CmdSQL = CmdSQL & " AND A.COD_BANCO *= C.COD_BANCO"
CmdSQL = CmdSQL & " AND A.EMPRESA *= D.COD_EMPRESA"
CmdSQL = CmdSQL & " AND ((A.dta_confirmacao is null AND status =
0) or status = 1)"
CmdSQL = CmdSQL & " AND A.SINAL ='C'"
CmdSQL = CmdSQL & " And A.Empresa = '5518'"
CmdSQL = CmdSQL & " and A.cod_banco = 745"
CmdSQL = CmdSQL & " And A.TIP_PAGTO <> 0"
CmdSQL = CmdSQL & " and (A.TIP_PAGTO > 1 OR B.INF_COMP_BOLETO IS
NOT NULL)"
CmdSQL = CmdSQL & " And A.DTA_VCTO_TITULO BETWEEN CONVERT
(DATETIME," & "'" & Format(Generico.DataI, "YYYYMMDD") & "'" & ", 103)
AND CONVERT(DATETIME," & "'" & Format(Generico.DataF, "YYYYMMDD") &
"'" & ",103)"
CmdSQL = CmdSQL & " And A.DTA_CONFIRMACAO IS NULL"
CmdSQL = CmdSQL & " AND A.DTA_AGENDAMENTO IS NULL"
CmdSQL = CmdSQL & " AND A.DTA_LIQUIDACAO_TITULO IS NULL"
CmdSQL = CmdSQL & " AND A.STATUS=0"

CmdSQL = CmdSQL & " Order By"
CmdSQL = CmdSQL & " A.status,"
CmdSQL = CmdSQL & " A.tip_pagto,"
CmdSQL = CmdSQL & " A.Num_Banco_Fornec"

If Not gfExecSQL(CmdSQL, 0) Then
MsgBox "Ocorreu um Erro ao Acessar o SqlServer. Contate um
Analista Responsável.", vbCritical
Exit Function
End If

If gdynaux.RowCount > 0 Then
FRM_Interf.HM_Importa.Max = gdynaux.RowCount
FRM_Interf.HM_Importa.Value = 0
End If

Set SS = gdynaux

Contador_Number = 1
Contador = PegaContador(False, 0) 'Pego o próximo numero do
Contador (A Alemanha usa para controle interno do FinNavigate)

Do While Not SS.EOF


If SS("Tip_Pagto") = 1 Then
If Not IsNull(SS("Val_Boleto")) Then
''Val_Titulo_Boleto = RecTitulo("Val_Boleto")
Val_Titulo_Boleto = troca_ponto_virgula(SS
("Val_Boleto"))
Else
Val_Titulo_Boleto = 0#
End If
Else
Val_Titulo_Boleto = 0#
End If

If SS("Val_Titulo") < "1.00" Then
Call MsgBox("Titulo com valor inferior à R$1,00." _
& vbCrLf & "Verificar!" _
& vbCrLf & "A aplicação será encerrada." _
, vbCritical, "PagFor - Aviso")
End
End If

If SS("Val_Titulo") = ".00" Then Val_Titulo = 0 Else
Val_Titulo = SS("Val_Titulo")
If SS("Val_Liquido_Titulo") = ".00" Then Val_Liquido = 0 Else
Val_Liquido = SS("Val_Liquido_Titulo")
If SS("Val_Desconto_Titulo") = ".00" Then Val_Desconto = 0
Else Val_Desconto = SS("Val_Desconto_Titulo")
If SS("Val_Acrescimo_Titulo") = ".00" Then Val_Acrescimo = 0
Else Val_Acrescimo = SS("Val_Acrescimo_Titulo")

TotalVal = (TotalVal + SS("Val_Titulo")) - Val_Desconto +
Val_Acrescimo 'Alterado



'===========CAMPO=================================================================================DESCRIÇÃO===============================================OBRIGATÓRIO
(S/N/D)==
Registro =
"P"
'01- Payment S
Registro = Registro & "|" & Format(Date,
"YYYYMMDD") '02- Date of
transmission S
Registro = Registro & "|" & Format(Time,
"HHMMSS") '03- Time of
transmission S
Registro = Registro & "|" & Format(Contador,
"0000000000000000") '04- Reference
number S
Registro = Registro & "|" &
"X"
'05- Test Mark N
Registro = Registro & "|" &
"PEX"
'06- Payment type S
Registro = Registro & "|" & Format(Contador_Number,
"0000000000000000") '07- Payment
number S
Registro = Registro & "|" &
"ORG"
'08- Function of the payment message S
Registro = Registro & "|" & Format(SS("DTA_EMISSAO_TITULO"),
"YYYYMMDD") '09- Date of the file
generation S
Registro = Registro & "|" & Format(SS("DTA_VCTO_TITULO"),
"YYYYMMDD") '10- Value date (data da
transferência) S
Registro = Registro & "|" & SS
("NUM_CONTA") '11-
Account number S
Registro = Registro &
"|"
'12- Payer check digits N
Registro = Registro &
"|"
'13- Payer postgiro flag N
Registro = Registro & "|" & Mid(SS("NOM_EMPRESA"), 1,
35) '14- Payer
name S
Registro = Registro &
"|"
'15- Payer name 2 N
If SS("COD_MOEDA") = 9 Or IsNull(SS("COD_MOEDA")) Then Valor =
"BRL" Else Valor = ""
Registro = Registro & "|" &
Valor
'16- Payer account currency S
Registro = Registro & "|" &
"CITIBRBRXXX"
'17- Payer account swith code D
Registro = Registro & "|" &
"002"
'18- Payer account swift code qualifier D
Registro = Registro & "|" & "" 'SS
("NUM_CONTA") '19-
Payer account NSC D
Registro = Registro & "|" &
"999"
'20- Payer account NSC Qualifier N
Registro = Registro & "|" & Mid(SS("NOM_BANCO"), 1,
70) '21- Payer account bank
name S
If IsNull(SS("CID_BANCO")) = False Then Valor = SS
("CID_BANCO") Else Valor = ""
Registro = Registro & "|" & Mid(Valor, 1,
70) '22- Payer
account bank branch N
Registro = Registro & "|" & Mid(SS("PAIS_BANCO"), 1,
2) '23- Payer bank
country S

'TIP_PAGTO = 1 => TITULO
If SS("TIP_PAGTO") = 1
Then
'24- Amount of the payment transfer S
Registro = Registro & "|" & Mid(troca_ponto_virgula(SS
("VAL_BOLETO")) * 100 / 100, 1, 18)
Else
Registro = Registro & "|" & Mid(troca_ponto_virgula(SS
("Val_Liquido_Titulo")) * 100 / 100, 1, 18)
End If

If SS("COD_MOEDA") = 9 Or IsNull(SS("COD_MOEDA")) Then Valor =
"BRL" Else Valor = ""
Registro = Registro & "|" &
Valor
'25- Currency S
Registro = Registro & "|" & Mid(SS("NUM_FATURA"), 1,
35) '26- Reference for the
transaction S

'TIP_PAGTO = 1 => TITULO
Registro = Registro & "|" &
"U"
'27- Payment type S
Registro = Registro &
"|"
'28- Share of costs N
'Conta do beneficiario Codigo do Banco + Conta Corrente +
Digito C/C
Numero_Conta_Beneficiario = SS("NUM_CCORRENTE_FORNEC") & SS
("NUM_DIG_CCORRENTE_FORNEC")
Registro = Registro & "|" & Mid(Numero_Conta_Beneficiario, 1,
35) '29- Beneficiary account
number S
Registro = Registro &
"|"
'30- Beneficiary check digits N
Registro = Registro &
"|"
'31- Beneficiary postgiro flag N
Registro = Registro & "|" & Mid(SS("NOM_FORNEC"), 1,
35) '32- Beneficiary name
1 S
Registro = Registro &
"|"
'33- Beneficiary name 2 N
Registro = Registro & "|" &
"BRL"
'34- Beneficiary account currency N
Registro = Registro & "|" &
"CITIBRBRXXX"
'35- Beneficiary account swift code D
Registro = Registro & "|" &
"002"
'36- Bebeficiary account swift code qualifier D
Registro = Registro & "|" & Format(Left(SS
("NUM_BANCO_FORNEC"), 3), "000") & _
Format(Left(SS
("NUM_AGENCIA_FORNEC"), 4), "0000") '37- Beneficiary
account NSC D
Registro = Registro & "|" &
"076"
'38- Beneficiary account NSC qualifier D
Registro = Registro & "|" & "Banco CitiBank SA, Paulista,
SP" '39- Beneficiary bank
name S
Registro = Registro &
"|"
'40- Beneficiary bank branch N
Registro = Registro & "|" &
"BR"
'41- Beneficiary bank country S
Registro = Registro & "|" &
""
'42- Beneficiary name N
Registro = Registro &
"|"
'43- Beneficiary name N
Registro = Registro &
"|"
'44- Beneficiary name N
Registro = Registro &
"|"
'45- Beneficiary name N
Registro = Registro & "|" & Mid(SS("END_FORNEC"), 1,
35) '46- Beneficiary
address N
Registro = Registro &
"|"
'47- Beneficiary address N
Registro = Registro &
"|"
'48- Beneficiary address N
Registro = Registro & "|" & Mid(SS("CIDADE_FORNEC"), 1,
35) '49- Beneficiary
town N
Registro = Registro & "|" & SS
("REGION_FORNEC") '50-
Beneficiary region/state N
Registro = Registro & "|" & Left(SS("CEP_FORNEC"),
9) '51- Beneficiary zip/
postal code N
Registro = Registro & "|" &
"BR"
'52- Beneficiary country N
Registro = Registro & "|" & Mid(SS("NOM_EMPRESA"), 1,
35) '53- Ordering party
name S
Registro = Registro &
"|"
'54- Ordering party name N
Registro = Registro &
"|"
'55- Ordering party name N
Registro = Registro &
"|"
'56- Ordering party name N
Registro = Registro & "|" & "Av dos Autonomistas
4229" '57- Ordering party
address N
Registro = Registro &
"|"
'58- Ordering party address N
Registro = Registro &
"|"
'59- Ordering party address N
Registro = Registro & "|" &
"Osasco"
'60- Ordering party address N
Registro = Registro &
"|"
'61- Ordering party region/state N
Registro = Registro & "|" &
"06090-901"
'62- Ordering party zip/postal code N
Registro = Registro &
"|"
'63- Ordering party country N
Registro = Registro & "|" &
"BR"
'64- LZB qualifier D
Registro = Registro &
"|"
'65- LZB notification D
Registro = Registro &
"|"
'66- LZB notification addendum D
Registro = Registro &
"|"
'67- LZB notification addendum D
Registro = Registro & "|" & Mid(SS("NUM_REFERENCIA"), 1,
70) '68-
Remittance S
Registro = Registro &
"|"
'69- Remittance 2 N
Registro = Registro &
"|"
'70- Remittance 3 N
Registro = Registro &
"|"
'71- Remittance 4 N
Registro = Registro &
"|"
'72- Remittance 5 N
Registro = Registro &
"|"
'73- Reserved field N
Registro = Registro &
"|"
'74- Reserved field N
Registro = Registro &
"|"
'75- Reserved field N
Registro = Registro &
"|"
'76- Reserved field N
Registro = Registro & "|" & Mid(SS("NOM_FORNEC"), 1,
35) '77- Contact
information S
Registro = Registro & "|" & Mid(SS("TEL_FORNEC"), 1,
35) '78- Contact telephone
number S
Registro = Registro & "|" & Mid(SS("COD_BANCO") & "PM" & SS
("NOM_EMPRESA"), 1, 30) '79- Ordering party
identification S
Registro = Registro &
"|"
'80- Beneficiary IBAN N
'Alteração feita por Henrique Bizarria em 17/09/2009, inclusão do
IFA_NUMBER 12 10
Registro = Registro & "|" & Left(SS("IFA_NUMBER"),
10) '81- Business partner
info S
Registro = Registro & "|" &
"*IF"
'82- Business partner info S
Registro = Registro & "|" & Mid(SS("COD_FORNEC"), 1,
35) '83- Tax
number N
Registro = Registro &
"|"
'84- Value added tax (VAT) number N
Registro = Registro &
"|"
'85- DUNS (Data Universal Numbering System) number N
Registro = Registro &
"|"
'86- Change commerce registration number N
Registro = Registro &
"|"
'87- Person registration number N


ReDim Preserve aNumFatura(UBound(aNumFatura) + 1)
aNumFatura(UBound(aNumFatura)) = SS("Num_Fatura")

ReDim Preserve aAnoFatura(UBound(aAnoFatura) + 1)
aAnoFatura(UBound(aAnoFatura)) = SS("ANO_Fatura")

'Alteração Efetuada em 14/05/2009 - Solicitação
'Contador = Contador + 1
Contador_Number = Contador_Number + 1

Print #Handle, Registro
SS.MoveNext
FRM_Interf.HM_Importa.Value = FRM_Interf.HM_Importa.Value + 1

DoEvents

Loop

'Guardo o numero do Contador (A Alemanha usa para controle interno
do FinNavigate)
Contador = Contador + 1
Call PegaContador(True, Contador)

If SS.RowCount > 0 Then

NumBordero = Val(Prox_Num_Lote("BORDERO", 9999))
CRBorderos = CRBorderos & IIf(CRBorderos = "", "", ",") & Trim
(Str(NumBordero))

Dim i As Integer

For i = 0 To UBound(aNumFatura)

Dim lsSqlWhere As String

If Trim(aNumFatura(i)) <> "" Then

lsSqlWhere = " AND NUM_FATURA = '" & aNumFatura(i) &
"'"
lsSqlWhere = lsSqlWhere & " AND ANO_FATURA = '" &
aAnoFatura(i) & "'"

'Atualiza Quando Normal
CmdSQL = "UPDATE Titulos_Pagar set dta_confirmacao =
CONVERT(DATETIME,CONVERT(CHAR(10), CURRENT_TIMESTAMP, 103),103),
NUM_BORDERO=" & NumBordero
CmdSQL = CmdSQL & " WHere "
CmdSQL = CmdSQL & "(dta_confirmacao is null or status
= 1) AND SINAL = 'C' "
CmdSQL = CmdSQL & "And Empresa = '" & Empresa & "' and
cod_banco = 745 and status = 0 "
CmdSQL = CmdSQL & "And (TIP_PAGTO > 1 OR COD_FORNEC +
NUM_TITULO + EMPRESA IN (SELECT COD_FORNEC_BOLETO + NUM_TITULO_BOLETO
+ COD_EMPRESA FROM BOLETOS_PAGAR))"
CmdSQL = CmdSQL & lsSqlWhere

If Not gfExecSQL(CmdSQL, 0) Then
MsgBox "Ocorreu um Erro ao Acessar o SqlServer.
Contate um Analista Responsável.", vbCritical
Exit Function
End If

'Atualiza Quando Cancelado
CmdSQL = "UPDATE Titulos_Pagar set dta_confirmacao =
CONVERT(DATETIME,CONVERT(CHAR(10), CURRENT_TIMESTAMP, 103),103),
STATUS = 2, NUM_BORDERO = " & NumBordero & " WHere "
CmdSQL = CmdSQL & "(dta_confirmacao is null or status
= 1) AND SINAL = 'C' "
CmdSQL = CmdSQL & "And Empresa = '" & Empresa & "' and
cod_banco = 745 and status = 1"
CmdSQL = CmdSQL & lsSqlWhere

If Not gfExecSQL(CmdSQL, 0) Then
MsgBox "Ocorreu um Erro ao Acessar o SqlServer.
Contate um Analista Responsável.", vbCritical
Exit Function
End If

End If

Next

CmdSQL = "INSERT INTO ARQUIVOS (ARQ_DTA, ARQ_VLR_INC,
ARQ_VLR_CNC, ARQ_NOM, ARQ_NUM_BOR, ARQ_ORI, ARQ_QTD)"
CmdSQL = CmdSQL & " VALUES "
CmdSQL = CmdSQL & "(CURRENT_TIMESTAMP, " & gfFVO(TotalVal -
TotalValCanc, 2) & ", " & gfFVO(TotalValCanc, 2) & ", '" &
FRM_Interf.LbArq.Caption & "', " & NumBordero & ", 'E'," & NumRegs - 1
& ")"
If Not gfExecSQL(CmdSQL, 0) Then
Exit Function
End If

End If

Exit Function

trata_Erro:
Mensagem_de_Erro ("GeraTransacaoCitibank")
MsgBox "Erro na Geração dos Borderôs. Favor Contactar o Analista
Responsável.", vbCritical

End Function

Gustavo Almeida

unread,
Oct 16, 2009, 8:20:35 AM10/16/09
to vb6b...@googlegroups.com
Então, cara...
 
Seu código tá muito grande e fica difícil entender...
Mas segue abaixo a rotina pra criar um arquivo TXT em VB6:
 
 

'Abrindo o arquivo
Open "C:\TEXTE.TXT" for Append as #1
    'Criando linhas em branco no arquivo
    Print #1, ""
    'Criando linhas com informação no arquivo
    Print #1, "Fácil! não?"
    'Depois é só fechar o arquivo:
Close #1
 
Esse comando aí, cria um arquivo ou então apenas inclui novas linhas, caso o arquivo já exista...
 
É só adaptar aí no meio do seu código.
 
 
----- Original Message -----
Reply all
Reply to author
Forward
0 new messages