Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print to certain location in a file?

Status
Not open for further replies.

demoniac

Programmer
Jun 14, 2001
63
US
Hello, I need to open up an existing file, go to a certain column, row, and print something at that point into the file. I can open and print to the end just fine but I don't know how to move the pointer around in the file. Can someone help me? :eek:)

Thanks!
demoniac
 
Try opening the file in binary format

just an online-idea ......... :eek:)

Code:
Dim flen    As Long
Dim filepos As Long
Dim fp      As Integer


flen = FileLen("c:\file.txt")
fp = FreeFile
filepos = flen / 2

Open "c:\file.txt" For Binary As #fp
  Seek #fp, filepos  'im in the middle of the file
Close #fp
bluenote@uyuyuy.com
(excuse my english)
 
Well that would work but I wouldn't really know how to get to a specific line. Like I need to write to line 6. I've looked at the seek command and I don't think I can do it with that, it takes me to a certain column, but not row. :(

Thanks though :eek:)
demoniac
 
OK, lets see ............... you can open the file for input, then , if you want to write at line 6, you can:

Code:
fileno = FreeFile
open "c:\file.txt" for input as #fileno
do while not eof(fileno)
  
  lineno=lineno + 1
  if lineno = 5 then exit do 'you better try with lineno = 6 too
  Line Input #fileno,some_dummy_var$
  DoEvents
Loop

Print #fileno,"this is line 6!"

Close #fileno

Hope this can help you ::)


bluenote@uyuyuy.com
(excuse my english)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top