|
-
Jul 15th, 2000, 05:39 AM
#1
Thread Starter
Hyperactive Member
Hello everybody. Here's my latest problem: I have to keep track of a few sets of guys-about 8 sets of 20 guys each. They have a name, number, and postion associated with each of them. I want to do two things; Turn a listview with the 3 columns (#,Name,Pos) and the completed list of names into a file (and eventually have about 8 files with the 20 guys' data), and I want to read from that file and put it back in a listview.
Thanks in advance,
bob
-
Jul 15th, 2000, 05:56 AM
#2
a nice clean way:
set up a UDT with the attributes you want, then declare an array of these new UDT's.
copy all the data from the list into the UDT array, and then open the file for random, and simple PUT the array into the file (don't worry about fields getting messed up, the PC takes care of all that). Now write code to open the file again as (random), and GET the array back (ps you must declare the new array to have the same number of elements as when the file was written or you may miss some records out of the array).
then loop through each UDT in the array and using its properties, add them to the blank list.
Email me if you want a better explanation.
-
Jul 15th, 2000, 10:00 AM
#3
New Member
wossname, can you elaberate on that please,
I know I didnt post the question but your answer sounds interesting.
how do you put the User Defined Type into the file?
i understand write and print statements, but what do you use with random files?
-
Jul 15th, 2000, 10:21 AM
#4
ok, since you asked so politely!
Code:
Open "C:\MyFile.txt" For Random as #1 Len = len(MyVariable)
right then, lets run through it.
'Random' tells VB that you want to open the file in non-sequential mode ('Output' or 'Append' both deal with sequential files). 'Len =' tells VB that each chunk of data that you read or write has this length.
if you look in the MSDN library it will give you a better idea, but here goes:
instead of the normal 'Print' or 'Line Input' commands, in random mode you should usually use 'Get' and 'Put'.
PUT: takes data from a named variable and outputs it in binary form (not necessarily ascii) to the open file.
GET: reads a certain number of bytes from the file and drops them into a named variable.
heres the clever bit: depending on the value of 'Len', the put and get commands will look at different parts of a file that relate to the record number (specified in the actual get/put command line)
an example, this code will read the integer in the 15th position in a text file, and insert this value into an existing variable: (assume the file is full of integers)
Code:
Dim MyInteger as integer
open "C:\MyFile.txt" for random as #1 Len = len(MyInteger)
get #1, 15, MyInteger
close #1
use the same code to write an integer back to the same place in the file, but change the 3rd line to read
'Put #1, 15, MyInteger'
Is this OK?
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
|