when editing it does it well on the screen
but it doesn't save the data correctly
example
Option Explicit
Private Type molde_agenda
id As String
nombre As String * 40
imagen As String * 250
End Type
Dim Datos As molde_agenda
Dim DatosTemp As molde_agenda
Dim FileFree As Integer
Dim FileTemp As Integer
Dim RegActual As Long
Dim RegUltimo As Long
Dim RegActualTemp As Long
Dim Pos As Integer, p As Integer
Dim reg As Integer
Private Sub Command1_Click()
Call Image_Click
End Sub
Private Sub Command2_Click()
'New
List1.Clear
txtNombre = ""
txtImagen = ""
Image1.Picture = Nothing
txtNombre.SetFocus
Dim c As Integer
Dim st As String
st = App.Path & "\Datos.txt"
FileFree = FreeFile
Open st For Random As FileFree Len = Len(Datos)
RegUltimo = LOF(1) / Len(Datos)
If RegUltimo = 0 Then
RegUltimo = 1
End If
Get #FileFree, RegUltimo, Datos
c = Val(Datos.id)
Text1 = c + 1
RegActual = 1
Close #FileFree
End Sub
Private Sub Command3_Click()
'Save
Dim st As String
Dim g As Integer
st = App.Path & "\Datos.txt"
FileFree = FreeFile
Open st For Random As FileFree Len = Len(Datos)
Dim Dire As String
Dire = App.Path & "\imagenes\" & txtImagen
With Datos
.id = Text1.Text
.nombre = txtNombre.Text
.imagen = txtImagen.Text
End With
Put #FileFree, LOF(1) / Len(Datos) + 1, Datos
List1.AddItem Val(Text1.Text) & vbTab & txtNombre.Text & vbTab & txtImagen.Text
SavePicture Image1.Picture, Dire
Close #1
txtNombre = ""
txtImagen = ""
Image1.Picture = Nothing
txtNombre.SetFocus
End Sub
Private Sub Command4_Click()
'Edit
Dim item As String
Dim st As String
Dim posicion As Integer
Dim i As Integer
Dim encontrado As Boolean
Dim Dire As String
If List1.ListIndex > -1 Then
List1.RemoveItem List1.ListIndex
End If
item = Text1.Text & vbTab & txtNombre.Text & vbTab & txtImagen.Text
List1.List(List1.ListIndex) = item
st = App.Path & "\Datos.txt"
FileFree = FreeFile
Open st For Random As FileFree Len = Len(Datos)
Dire = App.Path & "\imagenes\" & txtImagen
For i = 1 To LOF(FileFree) \ Len(Datos)
Get #FileFree, i, Datos
If Datos.id = Text2.Text Then
encontrado = True
posicion = i
Exit For
End If
Next i
'If encontrado Then
With Datos
.id = Text1.Text
.nombre = txtNombre.Text
.imagen = txtImagen.Text
End With
Put #FileFree, List1.ListIndex + 2, Datos
SavePicture Image1.Picture, Dire
'End If
Close #FileFree
End Sub
Private Sub Command6_Click()
End
End Sub
Private Sub Command8_Click()
'Read
Dim nombrearch
Dim encontrado As Boolean
Dim noreg As Integer
nombrearch = App.Path & "\Datos.txt"
Open nombrearch For Random As #1 Len = Len(Datos)
RegUltimo = LOF(1) / Len(Datos)
List1.Clear
For noreg = 1 To RegUltimo
Get 1, , Datos
If Text2.Text = Datos.id Then
List1.AddItem Datos.id & vbTab & Datos.nombre & vbTab & Datos.imagen
End If
Next noreg
Close #1
If Text2.Text > Datos.id Or Text2.Text = "" Then MsgBox "The name does not exist, thanks", vbCritical
End Sub
Private Sub Form_Load()
Dim c As Integer
Dim st As String
st = App.Path & "\Datos.txt"
FileFree = FreeFile
Open st For Random As FileFree Len = Len(Datos)
RegUltimo = LOF(1) / Len(Datos)
If RegUltimo = 0 Then
RegUltimo = 1
End If
Get #FileFree, RegUltimo, Datos
c = Val(Datos.id)
Text1 = c + 1
RegActual = 1
Close #FileFree
End Sub
Private Sub Image_Click()
CommonDialog1.CancelError = False
CommonDialog1.InitDir = App.Path & "\imagenes\" & txtImagen
CommonDialog1.ShowOpen
On Error Resume Next
Image1.Picture = LoadPicture(CommonDialog1.FileName)
txtImagen.Text = Dir(CommonDialog1.FileName)
If Err.Number = 53 Then
Image1.Picture = LoadPicture("")
End If
End Sub
Private Sub List1_Click()
Dim nombrearch As String
Dim noreg As Integer
Dim Dire As String
Dire = App.Path & "\imagenes\" & txtImagen.Text
If List1.ListIndex < 0 Then
MsgBox "NingĂșn elemento ha sido seleccionado", vbInformation
Exit Sub
End If
Dim Dati() As String
Dati = Split(List1.List(List1.ListIndex), vbTab)
Text1.Text = Dati(0)
txtNombre.Text = Dati(1)
txtImagen.Text = Dati(2)
Image1.Picture = LoadPicture(App.Path & "\imagenes\" & txtImagen.Text)
End Sub
I put all the code because it does not accept me to send the file