I'm building a simple app in Visual Basic for school. It's a TNR cat record locator.
Goal: Enter cat's name and details, submit data, data writes to text file and saves cat name as entry in a list box. When clicking a cat name in the list box, the cat's other data populates in a table or collection of text boxes.
I'm not sure how to make the last part happen, where I click on a name in the list box and populate the cat's data.
I can't find a way to do this that makes sense, since I'm still pretty new to the language and programming. Here's my code so far:
Public Class Form1
' Save input data to text file
Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("C:\Users\dkennedy2009\Documents\tnr_record.txt", True)
file.WriteLine(inptName.Text & inptLocation.Text & inptSex.Text & inptAge.Text & inptFeral.Text & inptCoat.Text & inptTrapped.Text & inptTrapDate.Text & inptVetDate.Text & inptFixDate.Text & inptReleaseDate.Text)
file.Close()
End Sub
' Create an array for accessing specific lines of data from .txt file:
Sub read_whole_file()
Dim sFile As String, sWhole As String
Dim v As Variant
sFile = "C:\Users\dkennedy2009\Documents\tnr_record.txt"
Open sFile For Input As #1
sWhole = Input$(LOF(1), 1)
Close #1
v = Split(sWhole, vbNewLine)
End Sub
' Add saved cat to list
Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
lstCats.Items.Add(inptName.Text)
End Sub
' Delete a cat from list
Private Sub BtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
lstCats.Items.Remove(lstCats.SelectedItem)
End Sub
' Code for displaying selected cat's details
End Class
And here's an image of the app:
