Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/04/2012, 16:19
tienda
 
Fecha de Ingreso: diciembre-2011
Mensajes: 70
Antigüedad: 12 años, 4 meses
Puntos: 2
Respuesta: procedimiento impresion ticket

bueno, nadie me ha ayudado así que lo hago yo mismo por si algún día alguien lo necesita, funciona bien...
Código:
'Se declaran las constantes ya las funciones API del Sistema

Public Const GENERIC_WRITE = &H40000000 
Public Const OPEN_EXISTING = 3 
Public Const FILE_SHARE_WRITE = &H2 
Public LPTPORT As String 
Public hPort As Integer, hPortP As IntPtr 
Public retval As Integer
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer

Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer

Public Structure SECURITY_ATTRIBUTES 
Private nLength As Integer 
Private lpSecurityDescriptor As Integer 
Private bInheritHandle As Integer 
End Structure 

Ya despues en un boton copiamos y pegamos esto:

Dim SA As SECURITY_ATTRIBUTES 
Dim outFile As FileStream 
LPTPORT = "LPT1" 
hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0) 
hPortP = New IntPtr(hPort) 

Dim Safe As New Microsoft.Win32.SafeHandles.SafeFileHandle(hPortP, True) 
outFile = New System.IO.FileStream(Safe, IO.FileAccess.Write) 

Dim fileWriter As New StreamWriter(outFile) 
fileWriter.WriteLine(" " & " Nombre de Empresa") 
fileWriter.WriteLine(" " & " Direccion, etc ")
fileWriter.WriteLine(" " & " Fecha : " & Date.Today) 
fileWriter.WriteLine(" " & "---------------------------------------") 
fileWriter.WriteLine(" " & "Articulo " & " Precio " & " Cantidad " & " Total ") 
fileWriter.WriteLine(" " & "---------------------------------------")
'Aqui puede ir un ciclo For que lea el contenido de un DataSet que contenga los datos a imprimir por ejemplo
'O bueno de donde quieran imprimir los datos
fileWriter.WriteLine(" " & "---------------------------------------")
fileWriter.WriteLine(" " & " Total$ " & var_Total) 'Aqui obviamente la variable donde tienen el total
fileWriter.WriteLine(" " & "Gracias Por Su Compra")
fileWriter.Flush()