im fairly new to vb 6 and doing a course which requires a project.
in my project i need to save a name, age, and form of a user in a random access file when a button is pressed which i have done, and then when another button is pressed, display the name for each record in a list box which i have also managed.
the next bit is selecting a name from the list box, clicking another button(load user info) and displaying the records name, age and form in seperate text boxes.
this is my code so far for saving and loading into the list box
(module) Public Type recvar Name As String * 10 age As Integer Form As String * 2 End Type Option Explicit Dim users As recvar, position As Integer, position2 As Integer Private Sub cmdSave_Click() Open App.Path & "\userfile.txt" For Random As #1 Len = Len(users) users.Name = frmMain.txtSaveNme.Text users.age = frmMain.txtSaveAge.Text users.Form = frmMain.txtFormSave.Text Put #1, position2 + 1, users Close #1 position2 = position2 + 1 txtSaveNme.Text = "" txtSaveAge.Text = "" txtFormSave.Text = "" End Sub Private Sub cmdLoad_Click() position = 1 Open App.Path & "\userfile.txt" For Random As #1 Len = Len(users) Do While Not EOF(1) Get #1, position, users listUsers.AddItem (users.Name) position = position + 1 Loop Close #1 End Sub
then this is where i get stuck and don't know how get the record
number form the selected item in the list box (listUsers):
Private Sub cmdLaodInfo_Click() Open App.Path & "\userfile.txt" For Random As #1 Len = Len(users) Get #1, , users frmMain.txtLoadNme.Text = users.Name frmMain.txtLoadAge.Text = users.age frmMain.txtFormLoad.Text = users.Form Close #1 End Sub
please help !!