Hola soy corlo
estoy haciendo una mini aplicacion de guardar datos de factura y leerlos por pantalla, en archivo secuencial.
guardar datos lo hace bien
el problema esta en leer los datos de la factura en pantalla
el archivo es 1.txt y hay lo siguiente:
==============================
COMPROBANTE DE VENTA
==============================
TICKET Nº: 1 TIPO : CONTADO
FECHA : 20/11/2021 HORA : 20:30:59
-------------------------------------------------------
R.U.C/C.I : a
CLIENTE : a
===============================
CANTIDAD PRODUCTO PRECIO SUBTOTAL
===============================
12 r 8 96
3 k 1.5 4,5
===============================
TOTAL : 100,50
-------------------------------------------
GRACIAS POR SU COMPRA!
me sale todo mezclado
el código que tengo hasta ahora es el siguiente:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_SETTABSTOPS = &H192
Dim I As Integer
Dim orden As Integer 'numero de ticket
Dim fecha As Date 'para leer la fecha
Dim hora As Date 'para leer la hora
Dim contado As String 'para contado
Dim credito As String 'para credito
Dim cedu1 As String ' para el RUC/C.I
Dim nom1 As String ' para el cliente
'abajo son datos del list1
Dim cantidad As Integer
Dim producto As String * 12
Dim preciox As String * 8
Dim subtot As Double
'varible del total
Dim tot As Double
Private Sub Command4_Click()
End
End Sub
Private Sub Command5_Click()
'Nuevo registro
'//recuperar el dato.
Open App.Path & "\Numero1.txt" For Input As #1
Do While Not EOF(1)
Input #1, orden
Loop
Close #1
Txtnum = orden + 1
List1.Clear
txtCedula1.Text = ""
txtNombre1.Text = ""
total.Text = ""
txtCedula1.SetFocus
End Sub
Private Sub Command6_Click()
'Guardar Factura
Dim cantidadtotal As Double
Dim k As Integer
orden = Txtnum.Text
On Error GoTo salir
Open App.Path & "\Numero1.txt" For Append As #1
Print #1, Txtnum
Close #1
Dim bmx As String
bmx = App.Path + "\" + Txtnum + ".txt"
Open bmx For Append As #1
Txtnum = orden
Print #1,
Print #1,
Print #1,
Print #1, Tab(1); String(44, "=")
Print #1, Tab((44 - Len("COMPROBANTE DE VENTA")) \ 2); "COMPROBANTE DE VENTA"
Print #1, Tab(1); String(44, "=")
If Option1.Value = True Then
Print #1, Tab(1); "TICKET Nº: " & Txtnum.Text; Tab(44 - Len("TIPO : CONTADO")); "TIPO : CONTADO"
Else
Print #1, Tab(1); "TICKET Nº: " & Txtnum.Text; Tab(44 - Len("TIPO : CREDITO")); "TIPO : CREDITO"
End If
Print #1, Tab(1); "FECHA : " & Date; Tab(44 - Len("HORA : " & Time)); "HORA : " & Time
Print #1, Tab(1); String(44, "-")
Print #1, Tab(1); "R.U.C/C.I : " & txtCedula1.Text
Print #1, Tab(1); "CLIENTE : " & txtNombre1.Text
Print #1, Tab(1); String(44, "=")
Print #1, Tab(1); "CANTIDAD"; Tab(11); "PRODUCTO"; Tab(24); "PRECIO"; Tab(37); "SUBTOTAL"
Print #1, Tab(1); String(44, "=")
For k = 0 To List1.ListCount - 1
Print #1, List1.List(k)
Next k
Print #1, Tab(1); String(44, "=")
Print #1, Tab(15); "TOTAL : "; Tab(43 - Len(Format(total.Text, "#,##0.00"))); Format(total.Text, "#,##0.00")
Print #1, Tab(16); "-----------------------------"
Print #1,
Print #1, Tab((44 - Len("GRACIAS POR SU COMPRA!")) \ 2); "GRACIAS POR SU COMPRA!"
For I = 1 To 10
Print #1,
Next I
Close #1
Option1.Value = False
Option2.Value = False
txtCedula1.Text = ""
txtNombre1.Text = ""
List1.Clear
cant.Text = ""
prod.Text = ""
precio.Text = ""
subtotal.Text = ""
total.Text = ""
cant.SetFocus
Exit Sub
salir:
Dim msgb
msgb = MsgBox("Error Nº : [ " & Err.Number & " ]" & " " & Err.Description, vbOKCancel + vbInformation)
End Sub
Private Sub Command7_Click()
'Leer Factura
Dim tabs(0 To 3) As Long
tabs(0) = 20
tabs(1) = 60
tabs(2) = 95
tabs(3) = 138
' Set the tabs.
SendMessage List1.hwnd, LB_SETTABSTOPS, 4, tabs(1)
Dim str As String
Dim thj As String
Dim plo As Boolean
Dim j As Integer
Dim h As Integer
On Error GoTo lo
List1.Clear
thj = App.Path + "\" + Txtnum.Text + ".txt"
If Dir(thj) <> "" Then
Open thj For Input As #1
Input #1, orden
Txtnum.Text = orden
Input #1, fecha
Label4.Caption = fecha
Input #1, hora
Label5.Caption = hora
Input #1, contado
Input #1, credito
Input #1, cedu1, nom1
txtCedula1.Text = cedu1
txtNombre1.Text = nom1
While Not EOF(1)
Input #1, cantidad, producto, preciox, subtot
cant.Text = cantidad
prod.Text = producto
precio.Text = preciox
subtotal.Text = subtot
List1.AddItem cantidad & vbTab & producto & vbTab & preciox & vbTab & subtot
Wend
j = 0
For h = 0 To List1.ListCount - 1
j = j + Val(Split(List1.List(h), vbTab)(3))
Next h
total.Text = j
Close #1
End If
If contado= contado Then
Option1.Value = True
Else
If credito = credito Then
Option2.Value = True
End If
End If
Exit Sub
lo:
If Not plo = True Then
MsgBox "La Factura no existe, gracias", vbCritical
End If
End Sub
Private Sub Command8_Click()
'Agregar
Dim h As Integer
Dim j As Double
cantidad = cant.Text
producto = prod.Text
preciox = precio.Text
subtot = subtotal.Text
List1.AddItem cantidad & vbTab & producto & vbTab & preciox & vbTab & subtot
j = 0
For h = 0 To List1.ListCount - 1
j = j + Split(List1.List(h), vbTab)(3)
Next h
total.Text = Format(j, "#,##0.00")
cant.Text = ""
prod.Text = ""
precio.Text = ""
subtotal.Text = ""
cant.SetFocus
End Sub
Private Sub Form_Load()
Dim tabs(0 To 3) As Long
tabs(0) = 20
tabs(1) = 123
tabs(2) = 237
tabs(3) = 370
SendMessage List1.hwnd, LB_SETTABSTOPS, 4, tabs(1)
Option1.Value = False
Option2.Value = False
Open App.Path & "\Numero1.txt" For Append As #1
Close #1
Open App.Path & "\Numero1.txt" For Append As #1
Close #1
'//recuperar el dato.
Open App.Path & "\Numero1.txt" For Input As #1
Do While Not EOF(1)
Input #1, orden
Loop
Close #1
Txtnum = orden + 1
End Sub
Private Sub List1_Click()
Text1.Text = Mid(List1.Text, 1, InStr(1, List1.Text, " ") - 1)
Text2.Text = Mid(List1.Text, InStr(1, List1.Text, " ") + 1)
I = List1.ListIndex
End Sub
Private Sub Option1_Click()
Option2.Value = False
End Sub
Private Sub Option2_Click()
Option1.Value = False
End Sub
Private Sub precio_KeyUp(KeyCode As Integer, Shift As Integer)
subtotal.Text = cant.Text * Val(precio.Text)
End Sub
Private Sub Timer1_Timer()
Label4.Caption = Date
Label5.Caption = Format(Time, "hh:mm:ss")
End Sub
Gracias