dim getdata as string
getdata = Listbox1.list(1)
will return the data or string on position 1
or if you want to detect which data has been clicked use this
dim getpos as integer
getpos = listbox1.listindex
if index 1 is click getpos will hold the value of 1 or whatever index position is click on the listbox
you can use msgbox to display the value of getpos if you want to verify
hope it helps..
cguan_77
Nearly a Posting Virtuoso
1,317 posts since Apr 2007
Reputation Points: 19
Solved Threads: 115
yeah a unique record ID would be the best way to go, because what if you have more than one Matt? How then will you distinguish him from another Matt? The code however for what you have, without the need to complicate it with userid's, would be, in your "load" function, to make an array that keeps all the record data, and then sort through it when you want to pull up a specific item. For example:
global UserRecords() as recvar ' // Put This In Your Module
Private Sub cmdLoad_Click()
ReDim UserRecords(0)
position = 1
Open App.Path & "\userfile.txt" For Random As #1 Len = Len(users)
Do While Not EOF(1)
Get #1, position, users
If UBound(UserRecords()) > 0 Then
ReDim Preserve UserRecords(UBound(UserRecords()) + 1)
UserRecords(UBound(UserRecords())) = users
Else
UserRecords(0) = users
End If
listUsers.AddItem (users.Name)
position = position + 1
Loop
Close #1
End Sub
Now, you should have a global array, called "UserRecords()" which is an array of type "recvar" (users). At This point, later when you need to call up a record, you can pretty much do:
Private Sub cmdLaodInfo_Click()
for each xname in UserRecords()
if xname.Name = listUsers.list(listUsers.listindex)
frmMain.txtLoadNme.Text = xname.Name
frmMain.txtLoadAge.Text = xname.age
frmMain.txtFormLoad.Text = xname.Form
next xname
End Sub
or something like that (I haven't tested this, so, it could have bugs. You may need to adjust accordingly)
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
unless you are using option explicit, you don't need to declare it. Variables that are not declared in VB6 by default are of type variant. Variant is a powerful (but crappy, resource using) variable that basically gets implicitly cast based on how it's needed. So, if it's a number, but used as a string, then it becomes a string. If it's a string, that's used a integer, it becomes an integer...etc.
For each is a looping type that is sort of like a for loop, but you just tell it to loop through all of the known values of an array. In the code above, basically I say "for all of the items in the UserRecords() array, do this code" Since we are looping through an array of recvar (UserRecords()) then xname becomes a variable of type recvar between the words "for" and "next xname". Since xname is then of type recvar, xname has all of the elements of recvar, such as .Form, .Name, and .Age.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215