|
-
Jan 9th, 2001, 10:49 PM
#1
Thread Starter
Hyperactive Member
OK I have a project which has to use a sequential access file.
I can not use a .mdb file (drat!)
Anyways I can populate a listbox with the first field of the data (there are 5 fields per record). The listbox's populates fine.
Now when I click on (1) of the listbox entries
I want the (second field) to show up in a textbox
the (Third field) to show up on a second text box...and so on.
My question is simply this...How do you set the record pointer in a sequential access file to look at the specified field?
I tried an array, using the listbox.listindex...but to no avail.
Why the heck can't this client just use a .MDB???
Help!
Lee
...Hmmm no one knows??????????
[Edited by Lee M. on 01-09-2001 at 11:47 PM]
 Mahalo 
VB6(SP5), VC++, COBOL, Basic, JAVA
MBA, MCSD, MCSE, A+
Computer Forensics
-
Jan 10th, 2001, 01:39 AM
#2
PowerPoster
Lee, Basically you can read the File and store all the data into aarray during your ListBox control population. Hence you need not open the same sequential file again. But if you prefer to the sequential file on every new List item selected. Then juz go ahead.
Code:
Option Explicit
'Method 1
Private tmp
'Method 2
Private F1() As String
Private F2() As String
Private F3() As String
Private F4() As String
Private F5() As String
Private Idx As Long
Private Sub Form_Load()
Dim Buff As String
Idx = 1
Open "C:\Lee.dat" For Random As #1 Len = 20
While Not EOF(1)
Get #1, Idx, Buff
If Buff <> "" Then
tmp = Split(Buff, Chr(44), -1, vbTextCompare)
'Method 1
List1.AddItem tmp(0)
'Method 2
ReDim Preserve F1(Idx)
ReDim Preserve F2(Idx)
ReDim Preserve F3(Idx)
ReDim Preserve F4(Idx)
ReDim Preserve F5(Idx)
F1(Idx) = tmp(0)
F2(Idx) = tmp(1)
F3(Idx) = tmp(2)
F4(Idx) = tmp(3)
F5(Idx) = tmp(4)
End If
Idx = Idx + 1
Wend
Close #1
Erase tmp
End Sub
Private Sub List1_Click()
'Method 1
Dim buf As String
Open "C:\Lee.dat" For Random As #1 Len = 20
Get #1, List1.ListIndex + 1, buf
Close #1
MsgBox buf
'Method 2
MsgBox F1(List1.ListIndex + 1) & "," & _
F2(List1.ListIndex + 1) & "," & _
F3(List1.ListIndex + 1) & "," & _
F4(List1.ListIndex + 1) & "," & _
F5(List1.ListIndex + 1)
End Sub
Cheers!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|