Click to See Complete Forum and Search --> : Random Files, LstBox, & TxtBox
MarkDF
January 29th, 2000, 05:08 PM
I have a procedure that creates and stores data describing "people"(name, ht, wt,...) in a random access file. I also have a procedure to "query" that data for certain "people" and then display those "people" in a listbox. I now need to click on a "person" in the listbox and have the program fill txtboxes on the same form with the appropriate "personal info"(name, ht, wt...textbox for each). Am I making this harder than it's suppose to be? I'm new at this so that could be the case, but I can't get the program to list the selected "person's" info. When I get the program to do anything, it seems to use data from the last "person" in the random access file. Thanks to whoever can help me with this problem!!
Johnny101
February 15th, 2000, 06:01 PM
Is there some reason you aren't using a database to hold this info? If you can, you should try to at least keep this in an Access db, because things would be a lot easier for one. If you can't, then when the user selects a person to view, you are pretty much gonna have to start at line 1 and go through the entire file until you find the person you are looking for. eg:
Open fn for input as #1
While Not EOF(1)
Line input #1, sTemp
'obviously, you will either have to know how many characters the selected name is
If mid(sTemp,1,10) = sNameUserSelected then
'get the rest of the info from this line
End If
Wend
Close #1
Or, if the file is at least deliminated with something a "|" or "~" maybe, and the lastname was always in the second position you use the Split() function instead of trying the Mid function :
'open the file
Dim sInfo() as string
While Not EOF(1)
Line input #1, sTemp
sInfo = Split(sTemp,"|")
If sInfo(2) = sNameUserSelected then
'...
End If
Wend
The split function will return an array of the values seperated by the deliminator you tell it to look for.
Hope this helps/applies,
John
John Pirkey
MCSD
www.ShallowWaterSystems.com
Kyle Burns
February 16th, 2000, 01:58 PM
You could make a person class and fill a collection with objects of type "person". Use this collection to fill your list. As soon as the people or in the collection, your data file can be closed and left out of the rest of the operations. If you use "Name" as the key for the collection you could do something like this:
private Sub lstNames_Click()
Dim TempPerson as Person
set TempPerson = m_colPeople(lstNames.Text)
With TempPerson
txtHeight = .Height
txtWeight = .Weight
txtDogsFavoriteFood = .DogsFavoriteFood
'etc...
End With
set TempPerson = nothing
End Sub
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.