FUNCAO PARA IMPRESSORA SWEDA

USUARIO.EXCLUIDOS 31/05/2005 08:42:22
#86056
Alguem tem alguma funçao pra mandar dados para emitir um ECF em impressora SWEDA.
Preciso urgentemente.

Obrigado desde já.
MARIOZNETO 31/05/2005 10:31:55
#86104
Resposta escolhida
entre na página:

www.ultramax.com.br

e deixe uma mensagem Para Felipe solicitando ajuda...
com certeza ele vai ajudar...

espero ter ajudado...

Mario
MARIOZNETO 31/05/2005 10:42:08
#86109
'DECLARE AS APIS DA DLL SWEDA
Private Declare Function Abre Lib "SWECF.DLL" Alias "ECFOpen" (ByVal Numero As Long, ByVal tempo As Long, ByVal Log As Long, ByVal Mostra As Long) As Long
Private Declare Function Fecha Lib "SWECF.DLL" Alias "ECFClose" () As Long
Private Declare Function Grava Lib "SWECF.DLL" Alias "ECFWrite" (ByVal Comando As String) As Long
Private Declare Function Retorna Lib "SWECF.DLL" Alias "ECFRead" (ByVal Status As String, ByVal extensao As Long) As Long

'CRIE UMA FUNÇÃO PARA MANDAR O COMANDO PARA IMPRESSORA
Private Function GravaSweda(Comando) As Boolean
Dim retimp As Long, estado As String
retimp = Grava(Chr(27) & "." & Comando & "}")
If retimp = 0 Then
GravaSweda = True
'Else
' estado = Space(512)
' retimp = Retorna(estado, 512)
' MsgBox estado, vbInformation
End If
End Function

'ABRE PORTA DA SWEDA
'PORTAIMP é numérico, porta COM, coloque 1 caso esteja na com1
If Abre(PORTAIMP, 7, 0, False) = 0 Then
'AbriuPorta
Else
'Ocorreu erro
End If

'ABRE O CUPOM FISCAL
If GravaSweda("17" & Mid(codcli & Space(20), 1, 20)) Then
'AbrIU Cupom Fiscal
Else
'ERRO
End If

'vender um item
'OPÇÕES
'isencao
TribALQ = "I "
'naoincid
TribALQ = "N "
'Nenhum
TribALQ = "I "
'SubstituicaoTrib
TribALQ = "F "
'Tributado
TribALQ = "T" & tmpVar 'TMPVAR seria o índice da alíquota na impressora, 2 digitos, ex: 'T 1'

'é IMPORTANTE FORMATAR A QUANTIDADE DE DàGITOS
'COMPLETANDO COM ESPAÇOS OU ZEROS O RESTANTE
If GravaSweda("01" & Space(13 - Len(codpro)) & codpro & _
Replace(Format(quantidade, "0000.000"), ",", "") & _
"0" & Replace(Format(valUnit, "000000.00"), ",", "") & _
"0000" & Replace( _
Format( _
CCur(Format(quantidade, "0000.000")) * CCur(Format(valUnit, "000000.00")) _
, "000000.00"), ",", "") & DescricaoProd & _
TribALQ) Then
'vendeu item
Else
'Erro
End If


'SE TIVER DESCONTO, APLICA
'CVALOR = DESCONTO
If Cvalor > 0# Then
If GravaSweda("03" & Space(10) & _
Replace(Format(Cvalor, "0000000000.00"), ",", "") & _
"S") Then
'TOTALIZOU CUPOM
Else
'ERRO
End If
Else
'TOTALIZOU CUPOM
End If


'PARTE COMPLICADA, FECHAR CUPOM

'PEGA FORMAS DE PAGAMENTO
'Modalidades (Formas de pagamento) de 1 - 3
If Not GravaSweda("295") Then
GoTo fim:
End If

tmpStr = Space(512)
If Retorna(tmpStr, 512) = -1 Then
GoTo fim:
End If

'Remove dados iniciais e finais
tmpStr = Mid(tmpStr, 7, InStr(1, tmpStr, "}") - 7)

For cont2 = 0 To 2
'Identificador tributário
FormasPgto = FormasPgto & Mid(tmpStr, 30 + (cont2 * 15), 15) & Chr(0)
Next

'Modalidades (Formas de pagamento) de 4 - 10
If Not GravaSweda("296") Then
GoTo fim:
End If

tmpStr = Space(512)
If Retorna(tmpStr, 512) = -1 Then
GoTo fim:
End If

'Remove dados iniciais e finais
tmpStr = Mid(tmpStr, 7, InStr(1, tmpStr, "}") - 7)

For cont2 = 3 To 9
'Identificador tributário
FormasPgto = FormasPgto & Mid(tmpStr, 2 + (cont2 * 15), 15) & Chr(0)
Next

FormasPgto = Strings.Left(FormasPgto, Len(FormasPgto) - 1)

'FECHA CUPOM
'GRAVA EM MATRIZ FORMAS DE PAGAMENTO
tmpVar = Split(LCase(FormasPgto), Chr(0))

For ax = 0 To UBound(wforma)
'VERIFICA SE FORMA ESTà SENDO UTILIZADA
If VALORRECEBIDO <> "" Then
If CCur(VALORRECEBIDO) > 0# Then
'LOOP PARA PEGAR àNDICE DA FORMA DE PAGAMENTO
indPag = -1
For contagem = 0 To UBound(tmpVar)
If UCase(Trim(tmpVar(contagem))) = UCase(Trim(FORMADEPAGAMENTO)) Then
indPag = contagem
Exit For
End If
Next contagem
'Forma de pagamento não encontrada
If indPag = -1 Then
MsgBox "Forma de pagamento não cadastrada na impressora!", vbInformation
'ERRO
Exit Function
End If
strTemp = strTemp & Format(indPag + 1, "00") & Replace(Format(VALORRECEBIDO, String(10, "0") & ".00"), ",", "")
End If
End If
Next ax
'TOTALIZAR CUPOM EFETUA AS FORMAS DE PAGAMENTO
'If Not GravaSweda("10" & strTemp & "{" & space(80)) Then
'10|00|000000000001|{
If Not GravaSweda("10" & strTemp & "{") Then
'ERRO
Exit Function
Else
'FECHOU CUPOM
End If
'Atributo Número de caracteres por linha
'“0” (30h) 40 caracteres
'“1” (31h) 33 caracteres *
'“2” (32h) 20 caracteres
'If Len(Mensagem) < 21 Then
' ax = 2
'ElseIf Len(Mensagem) < 34 Then
' ax = 1
'Else
ax = 0
'End If
If Len(Mensagem) > 40 Then
Mensagem = Mid(Mensagem, 1, 40)
End If
Mensagem = CStr(ax) & Mensagem & Space(40 - Len(Mensagem))
strTemp = Mensagem
If Trim(codvend) <> "" Then
strTemp = CStr(ax) & Strings.Left("Atendido por: " & codvend & Space(40), 40) & strTemp
End If
strTemp = CStr(ax) & Strings.Left(" " & Format(cepcliente, "@@@@@-@@@") & _
"-" & cidadecliente & "-" & _
estadocliente & Space(40), 40) & strTemp
strTemp = CStr(ax) & Strings.Left("Endereço: " & _
enderecocliente & Space(40), 40) & strTemp

' If cnpj <> "" Then
' strTemp = CStr(ax) & Strings.Left(" CNPJ: " & _
' Format(cnpj, "@@.@@@.@@@/@@@@-@@") & Space(40), 40) & strTemp
' ElseIf cpf <> "" Then
' strTemp = CStr(ax) & Strings.Left(" CPF: " & _
' Format(cpf, "@@@.@@@.@@@-@@") & Space(40), 40) & strTemp
' Else
' strTemp = CStr(ax) & Strings.Left(" CÓ“DIGO: " & _
' Format(codcliente, "@@@.@@@.@@@/@@@@-@@") & Space(40), 40) & strTemp
' End If

strTemp = CStr(ax) & Strings.Left(" Cliente: " & _
nomecliente & Space(40), 40) & strTemp

If GravaSweda("12NN" & strTemp) Then
'FECHOU CUPOM
Else
'ERRO
End If
Tópico encerrado , respostas não são mais permitidas