'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 IntegerPublic Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As IntegerPublic 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 datosfileWriter.WriteLine(" " & "---------------------------------------")fileWriter.WriteLine(" " & " Total$ " & var_Total) 'Aqui obviamente la variable donde tienen el totalfileWriter.WriteLine(" " & "Gracias Por Su Compra")fileWriter.Flush()Funciona al 100%
No hay comentarios:
Publicar un comentario