I need to read the id of the datos.txt file

datos.txt file information:

   1       a       dreamstime_3361539.jpg
                                                                                                                                                                                                                                                                      1 b   dreamstime_7231733.jpg
                                                                                                                                                                                                                                                                      2 c   dreamstime_19009914.jpg
                                                                                                                                                                                                                                                                     2  d   dreamstime_66340321.jpg
                                                                                                                                                                                                                                                                     3  r   F100010793.jpg
                                                                                                                                                                                                                                                                     3  t   music-girl-1366-768-5394.jpg
                                                                                                                                                                                                                                                                     3  p   orig_shutterstock_5515123.jpg

when i put the value in text2.text in 1 it has to come out

    1   a   dreamstime_3361539.jpg
                                                                                                                                                                                                                                                                      1 b   dreamstime_7231733.jpg

in list1

when i put the value in text2.text in 2 it has to come out

   2    c   dreamstime_19009914.jpg
                                                                                                                                                                                                                                                                     2  d   dreamstime_66340321.jpg

in list1

when i put the value in text2.text in 3 it has to come out

   3    r   F100010793.jpg
                                                                                                                                                                                                                                                                     3  t   music-girl-1366-768-5394.jpg
                                                                                                                                                                                                                                                                     3  p   orig_shutterstock_5515123.jpg

in list1

thank you

Recommended Answers

All 6 Replies

Very few have Visual Basic 6 from 1998 installed and working. So let's go about this another way.

Post the passage of code that is problematic and tell what it is doing as well as what it should do. I wrote far too much in VB6 but we moved on about a decade ago.

What I'm doing is trying to read the id in text2.text and the command8_click button and list by id in list1.
now list all together

commented: That's fine but I can't load up your project. Few others can so by not posting the relevant code in the clear with your assessment, you see the issue? +17
 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
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)
  c = c + 1
         Text1 = c + 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




  For g = 0 To List1.ListCount - 1
  With Datos

       .nombre = List1.List(g) & vbCrLf


   End With

   Put #FileFree, LOF(1) / Len(Datos) + 1, Datos
 Next g
 SavePicture Image1.Picture, Dire
     Close #1
     List1.Clear
txtNombre = ""
txtImagen = ""
Image1.Picture = Nothing
txtNombre.SetFocus
End Sub

Private Sub Command6_Click()
End
End Sub

Private Sub Command7_Click()
'Add

   List1.AddItem Val(Text1.Text) & vbTab & txtNombre.Text & vbTab & txtImagen.Text





End Sub

Private Sub Command8_Click()
'Read


Call BuscarItems1(List1.List(List1.ListIndex))


End Sub




Private Sub BuscarItems1(ByVal strid As String)

    Dim item As String
 Dim tot As Integer
    List1.Clear



Dim n As Integer
Dim nombrearch, nombre As String
Dim encontrado As Boolean
Dim noreg As Long
nombrearch = App.Path & "\Datos.txt"
Open nombrearch For Random As #1 Len = Len(Datos)
encontrado = False
noreg = 1
RegUltimo = LOF(1) / Len(Datos)

   Do While Not EOF(1)
        Get 1, , Datos
        With Datos



            For tot = 0 To RegUltimo


               If RegUltimo > Text2.Text Then

                 item = .id & vbTab & .nombre & vbTab & .imagen

              End If



             Next tot

                Call List1.AddItem(item)


        End With
    Loop
  Close #1

  On Error Resume Next
If encontrado = False Then
MsgBox "The name does not exist, thanks", vbCritical
Close #1
End If
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

The code posted has extraneous blank lines and you didn't write where in the 200+ lines you felt the issue was.

Here, you get to work at the issue so you learn how to fix your code. For now you should be setting breakpoints so you can examine variables as your code runs. Are you aware of this feature?

I have managed to read the records but now the error message does not appear the name does not exist

'Read



Dim nombrearch
Dim encontrado As Boolean
Dim noreg As Integer
nombrearch = App.Path & "\Datos.txt"


On Error GoTo salida
Open nombrearch For Random As #1 Len = Len(Datos)
RegUltimo = LOF(1) / Len(Datos)
List1.Clear


            For noreg = 1 To RegUltimo

               Get 1, , Datos

               encontrado = True

              If Text2.Text = Datos.id Then

                 List1.AddItem Datos.id & vbTab & Datos.nombre & vbTab & Datos.imagen

              End If

            Next noreg


  Close #1
Exit Sub
salida:

If Not encontrado Then
MsgBox "The name does not exist, thanks", vbCritical
Close #1
End If

On line 21 encontrado is always set to True, so the If on line 36 will always be False.

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.