Option Explicit
Private Type Registro
nombre As String * 30
direccion As String * 25
poblacion As String * 30
telefono As String * 20
nif As String * 20
correo As String * 40
End Type
Dim forma As Registro
Private Type Type_Indices
Codigo_clientes As Integer
End Type
Const Prefix_Clientes = "Cliente" 'Asignamos un prefijo a las facturas para cuandos se guarden
Private numeros As Type_Indices
Private Sub Command1_Click()
'Nuevo Cliente
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text2.SetFocus
Dim intFile As Integer
intFile = FreeFile
numeros.Codigo_clientes = numeros.Codigo_clientes + 1
Label1.Caption = numeros.Codigo_clientes
'GUARDAMOS EL CODIGO DE LA NUEVA FACTURA
Open App.Path & "\clientes\tabla.txt" For Random As intFile
Put #intFile, , numeros
Close #intFile
Label2.Caption = Space(10) & "Cliente:"
End Sub
Private Sub Command2_Click()
'Guardar Cliente
Open App.Path & "\clientes\" & Text2.Text For Random As #1 Len = Len(forma)
forma.nombre = Text2.Text
forma.direccion = Text3.Text
forma.poblacion = Text4.Text
forma.telefono = Text5.Text
forma.nif = Text6.Text
forma.correo = Text7.Text
Put #1, LOF(1) / Len(forma) + 1, forma
List1.AddItem forma.nombre
Close #1
End Sub
Private Sub Command3_Click()
Dim n As Integer
Dim fencontrada As Boolean
Dim gh As String
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
List1.Clear
gh = App.Path & "\clientes" & "\" & Text1.Text
Open gh For Random As #1 Len = Len(forma)
For n = 1 To LOF(1) / Len(forma)
Get #1, n, forma
fencontrada = True
List1.AddItem forma.nombre
Text2.Text = forma.nombre
Text3.Text = forma.poblacion
Text4.Text = forma.direccion
Text5.Text = forma.telefono
Text6.Text = forma.nif
Text7.Text = forma.correo
Next n
Close #1
If Not fencontrada Then
MsgBox "El Cliente no existe.", vbCritical, "ERROR."
Kill gh
End If
End Sub
Private Sub Command6_Click()
'salir del programa
End
End Sub
Private Sub Form_Load()
Dim n As Integer
Dim gh As String
If Dir(App.Path & "\clientes", vbDirectory) = "" Then
If MsgBox("OK Directorio ¡Clientes! Creado.", vbOKCancel) = vbOK Then
MkDir (App.Path & "\clientes")
Else
MsgBox " Directorio ¡Clientes! no Creado."
Exit Sub
End If
End If
Dim intFile As Integer
intFile = FreeFile
Open App.Path & "\clientes\tabla.txt" For Random As intFile
Get #intFile, , numeros
Close #intFile
Label1.Caption = numeros.Codigo_clientes
List1.Clear
' aqui es donde no me lee todos los archivos de golpe en el list1
gh = App.Path & "\clientes\" & ".txt"
Open gh For Random As #1 Len = Len(forma)
While Not EOF(1)
Get #1, , forma
List1.AddItem forma.nombre
Wend
Close #1
End Sub