Hey everyone
Does anyone know how to open a file and add the "%" at the beginning and the end of a file.
Thanks
Reston
Printable View
Hey everyone
Does anyone know how to open a file and add the "%" at the beginning and the end of a file.
Thanks
Reston
I would simply say to read the file and then write it back.
You can either read it all into a variable then write it back to the same file or open the file (open "MYFILE.txt" for input as #1) and another temp file (open "MyTempFile.txt" for output as #2) and then read from one and write to the other. Then delete the old one (Kill) and rename the new one to the old one.
1)
You now have the whole file in MyString (string variable).Code:Open "MyFile.txt" for input as #1
Do
Line input #1, ReadNewLine
MyString = Mystring & ReadNewLine
loop until EOF(1)
close #1
Just open the file again and write
2)Code:Open "MyFile.txt" for output as #1
? #1, "%"
? #1, MyString
? #1, "%"
close #1
I didn't include the paths, you would have to include paths or it will write to the same path as you project (I think)... Even if you want it to write to your project path it is still better to use App.Path & "\MyFile.txt"Code:Open "MyFile.txt" for input as #1
Open "MyTempFile.txt" for output as #2
? #2, "%"
Do
Line Input #1, ReadNewLine
? #2, ReadNewLine
loop until EOF(1)
? #2, "%"
Close #1
Close #2
Kill "MyFile.txt"
Name "MyTempFile.txt" as "MyFile.txt"
Mike
Okay you need the code to look something like this...
Open "MyFile.txt" for output as #1
Print #1
Close #1
That works pretty good but when vb prints back to the file it's all on one line.
The input looks like this below.I need the file to be preserved like it was.
Thanks
Reston
O0000
M00
( Menu File: W.120 )
( 12-05-2006 19:00:41 )
N 1 G01G90G49G40G80G17
N 2 G91G28Z0
N 3 G91G28X0Y0A0.
N 4 T 12M06
N 5 G92X 119450 Y 151150 Z 229765 A- 80
N 6 G01G90Y 0 F 2000000
N 7 S 2700 M03
N 8 M08
N 9 G90A0.F 2000000
If you are using Print #1, [VARIABLE] (same as ? #1) then it shouldn't be one line.
The Print # ends each line.
Make sure your using Line Input # to get it.
I pasted your txt sample into a MyFile.txt file.
Then ran this code....
The text file that resulted was,Code:Open "MyFile.txt" For Input As #1
Open "MyTempFile.txt" For Output As #2
Print #2, "%"
Do
Line Input #1, ReadLine
Print #2, ReadLine
Loop Until EOF(1)
Print #2, "%"
Close #1
Close #2
Kill "MyFile.txt"
Name "MyTempFile.txt" As "MyFile.txt"
%
O0000
M00
( Menu File: W.120 )
( 12-05-2006 19:00:41 )
N 1 G01G90G49G40G80G17
N 2 G91G28Z0
N 3 G91G28X0Y0A0.
N 4 T 12M06
N 5 G92X 119450 Y 151150 Z 229765 A- 80
N 6 G01G90Y 0 F 2000000
N 7 S 2700 M03
N 8 M08
N 9 G90A0.F 2000000
%
I have attached the project files
Hey Thank for the help
Reston