Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Appending File Problem Posted by snoburnssb on 27 Apr 2005 at 4:24 PM
i need to write a script to modify a fairly large file only in certain places using the file system object model. i was thinking something like this:

'read entire file into array
set fil1 = fso.getfile(file)
set ts = fil1.openastextstream(forreading)
do until ts.atendofstream = true
n = n + 1
indata(n) = ts.readline
loop
NumberOfLines = n
ts.close

'output file line by line, making changes as needed
set fil1 = fso.getfile(file)
set ts = fil1.openastextstream(forwriting)
for n = 1 to NumberOfLines
'script that determines if im at a point where a change is to be made
ts.writeline indata(n)
next n
ts.close

someone please tell me there is an easier way to do this. im kindof new to visual basic. thanks!
Report
Re: Appending File Problem Posted by kapiloo7 on 28 Apr 2005 at 2:43 AM
: i need to write a script to modify a fairly large file only in certain places using the file system object model. i was thinking something like this:
:
: 'read entire file into array
: set fil1 = fso.getfile(file)
: set ts = fil1.openastextstream(forreading)
: do until ts.atendofstream = true
: n = n + 1
: indata(n) = ts.readline
: loop
: NumberOfLines = n
: ts.close
:
: 'output file line by line, making changes as needed
: set fil1 = fso.getfile(file)
: set ts = fil1.openastextstream(forwriting)
: for n = 1 to NumberOfLines
: 'script that determines if im at a point where a change is to be made
: ts.writeline indata(n)
: next n
: ts.close
:
: someone please tell me there is an easier way to do this. im kindof new to visual basic. thanks!
:

u can do one thing. read entire file into a string (strFile suppose)
.use REPLACE function, if u want to replace any text in file. if u just want to appent then conatenate new string to strFile and again write back the string (strFile) to file. and File System Object is not the only way to access files. u can use generic Open/Close functions.
hope i gave something u wanted.

Report
Re: Appending File Problem Posted by dokken2 on 28 Apr 2005 at 5:38 AM
: : i need to write a script to modify a fairly large file only in certain places using the file system object model. i was thinking something like this:
: :
: : 'read entire file into array
: : set fil1 = fso.getfile(file)
: : set ts = fil1.openastextstream(forreading)
: : do until ts.atendofstream = true
: : n = n + 1
: : indata(n) = ts.readline
: : loop
: : NumberOfLines = n
: : ts.close
: :
: : 'output file line by line, making changes as needed
: : set fil1 = fso.getfile(file)
: : set ts = fil1.openastextstream(forwriting)
: : for n = 1 to NumberOfLines
: : 'script that determines if im at a point where a change is to be made
: : ts.writeline indata(n)
: : next n
: : ts.close
: :
: : someone please tell me there is an easier way to do this. im kindof new to visual basic. thanks!
: :
:
: u can do one thing. read entire file into a string (strFile suppose)
: .use REPLACE function, if u want to replace any text in file. if u just want to appent then conatenate new string to strFile and again write back the string (strFile) to file. and File System Object is not the only way to access files. u can use generic Open/Close functions.
: hope i gave something u wanted.
:
:

If you only need to append then don't even need to read the file.
ie:

Open fname For Append As filenum 'APPEND TO FILE
Print #filenum, MyString
Close filenum

Report
Re: Appending File Problem Posted by snoburnssb on 28 Apr 2005 at 5:58 AM
This message was edited by snoburnssb at 2005-4-28 5:58:47

: : : i need to write a script to modify a fairly large file only in certain places using the file system object model. i was thinking something like this:
: : :
: : : 'read entire file into array
: : : set fil1 = fso.getfile(file)
: : : set ts = fil1.openastextstream(forreading)
: : : do until ts.atendofstream = true
: : : n = n + 1
: : : indata(n) = ts.readline
: : : loop
: : : NumberOfLines = n
: : : ts.close
: : :
: : : 'output file line by line, making changes as needed
: : : set fil1 = fso.getfile(file)
: : : set ts = fil1.openastextstream(forwriting)
: : : for n = 1 to NumberOfLines
: : : 'script that determines if im at a point where a change is to be made
: : : ts.writeline indata(n)
: : : next n
: : : ts.close
: : :
: : : someone please tell me there is an easier way to do this. im kindof new to visual basic. thanks!
: : :
: :
: : u can do one thing. read entire file into a string (strFile suppose)
: : .use REPLACE function, if u want to replace any text in file. if u just want to appent then conatenate new string to strFile and again write back the string (strFile) to file. and File System Object is not the only way to access files. u can use generic Open/Close functions.
: : hope i gave something u wanted.
: :
: :
:
: If you only need to append then don't even need to read the file.
: ie:
:
: Open fname For Append As filenum 'APPEND TO FILE
: Print #filenum, MyString
: Close filenum
:
:
>>
The REPLACE thing worked. Thanks!




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.