|
-
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
|