hey guys i need some a litle help with my vb.

i have a problem with my project
i cant delete a data in a file and i cant split the name,age and id if ever i click it, it will display above of it in FRMRETRIEVE

i have here all my code in the zip file

Private Sub cmdDelete_Click() // IHAVE ALSO PROBLEM
Dim i As Integer //WITH THIS DELETE
If rey.Text(lstData.List) = "true " Then //IT WILL NOT DELETE
If MsgBox("You want to delete this data" & rey.Text) Then
rey.RemoveItem (lstData.ListIndex)

Close #1
End If
End If

End Sub

Private Sub cmdRetrieve_Click()
Dim X As String
Open App.Path & "\rey.txt" For Input As #1
While Not EOF(1)
Line Input #1, X
lstData.AddItem (X)
Close 1
End Sub
Private Sub cmdSave_Click()
Dim i As Integer
i = lstData.ListIndex
lstData.List(i) = txtID.Text
lstData.List(i) = txtName.Text
lstData.List(i) = txtAge.Text
Open App.Path & "\rey.txt" For Output As #1
For i = 0 To lstData.ListCount - 1
Print #1, lstData.List(i)
Next i
Close 1
End Sub
Private Sub lstData_Click() // I HAVE A PROBLEM WITH THIS AREA
Dim i As Integer //IT WILL NOT SPLIT
i = lstData.ListIndex // IF I WILL CLICK THE LISTDATA
txtID.Text = lstData.List(i) // IT WILL BE SPLIT IN THE ABOVE
txtName.Text = lstData.List(i)
txtAge.Text = lstData.List(i)
End Sub

7 Years
Discussion Span
Last Post by vb5prgrmr

Okay, to split on the comma (,) you need to use...

THE Split Function!

Dim MyArray() As String
MyArray = Split(lstData.List(i), ",")
txtID.Text = MyArray(0)
txtName.Text = MyArray(1)
txtAge.Text = MyArray(2)

Then would it not be lstData.RemoveItem(i)?

And now for why you are having so many problems...

Tools>Options>Put a check next to Require Variable Declaration>OK

In future projects this will put Option Explicit at the top of all your forms and modules and will make you declare your variables. This will solve a lot of problems for you. In fact, you could manually put it in at the top of your existing forms and modules and this will help you out by pointing out your mistakes.

Good Luck

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.