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

Recommended Answers

All 3 Replies

You say that it does not save correctly and then again that it does not send the file. This is a lot of code and not clear enough of where you are stuck -
What error and on which line?
What does not save, what happens in which code that you want to save?
What file are you sending where using which code?

Lastly, VB6 has been dead for many years, is there a specific reason why you are using VB6, why not upgrade to .NET?

the issue to edit is on line 89 to 142

  '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


    With Datos
            .id = Text1.Text
           .nombre = txtNombre.Text
           .imagen = txtImagen.Text

       End With
    Put #FileFree, List1.ListIndex + 2, Datos


    SavePicture Image1.Picture, Dire


     Close #FileFree
    End Sub


The issue is that it does not save the modified data






 With Datos
            .id = Text1.Text
           .nombre = txtNombre.Text
           .imagen = txtImagen.Text

       End With
    Put #FileFree, List1.ListIndex + 2, Datos

for me it is not dead vb 6.0 thanks

commented: With so few having VB6 now, you need to move to a current release. Help will be hard to find. +17

As rproffit stated, you need to move to a current release, none of us have vb6 anymore so we can supply help but cannot test our own code so we will supply what we think is correct...

There might be a few issues you can check to solve your problem -

  1. Your code uses the Random mode for file handling. However, it's not clear if the 'Datos' variable used for the record structure is properly defined. Make sure you have defined it correctly in your code. You can define it as 'Type'. Make sure that the 'FileFree' variable is declared properly before the 'Open' statement, like 'Dim FileFree As Integer' -

    Type Datos
    id As String
    nombre As String
    imagen As String
    End Type

2)Instead of using the 'Open' statement, you should use the 'FileOpen' statement to open the file for writing. Also, use 'FileClose' to close the file after writing to it. Replace this line -
Open st For Random As FileFree Len = Len(Datos) with FileOpen(FileFree, st, OpenMode.Random, OpenAccess.Write, OpenShare.Default, Len(Datos))

Also, replace this line - Close #FileFree with FileClose(FileFree)

  1. Make sure that the 'Image1.Picture' control contains a valid picture before saving it. You can check if the 'Image1.Picture' (try to use proper naming conventions like MyImageToSave.Picture to make sense to readers like myself) is not 'Nothing' before calling 'SavePicture'. Also, make sure that the 'Dire' variable is the correct path and file extension for your image. To check before saving -

    If Not Image1.Picture Is Nothing Then
    SavePicture Image1.Picture, Dire & ".bmp"
    'change bmp with your file extension i.e. jpg etc...
    End If

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.