Author Topic: writing to a text file  (Read 2537 times)

Mark Laing

  • Sr. Member
  • ****
  • Posts: 311
writing to a text file
« on: December 17, 2007, 10:19:07 PM »
In the following code fragment, I know I'm opening and closing the file right because it come's up in Notepad, but how do I write to the file?  I get nowhere with Input# or Print#.

filename$ = "Timesheet"
Open "A", 1, filename$
'Input# 1, "Hello, World!"
Close 1
run$ = "c:\windows\notepad.exe ", filename$
run run$, 1

And for opening a file for random access I need the file length. How on earth do I get that?
« Last Edit: December 17, 2007, 10:30:45 PM by Mark Laing »

bdeck

  • Hero Member
  • *****
  • Posts: 825
Re: writing to a text file
« Reply #1 on: December 17, 2007, 11:40:50 PM »
Hi Mark,

Try this.


filename$ = "Timesheet"
Open "A", 1, filename$
print #1, "Hello, World!"      ' no space after #, space before # is optional
Close 1
run$ = "c:\windows\notepad.exe " + filename$    ' plus sign is more conventional, but comma works in DC
run run$, 1

Random access requires record length for data files, not file length. Choose whatever record size works for your application. The system will index that number of bytes between reads.

BD



« Last Edit: December 19, 2007, 09:01:45 AM by bdeck »