If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > FSO - Appending Replacements

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-20-03, 21:24
vextout vextout is offline
Registered User
 
Join Date: Jan 2003
Location: New York
Posts: 160
FSO - Appending Replacements

i am trying to read in a text file and replace certain words and write tit to a new text file. The problem im getting is how to append all the replacements. I tried readall and readline. I have to replace around 10 words. This is what i go so far

mf1 mf2 mf3 are all dim as string
Dim fso, txtOrg, txtNew
Dim oTmp As String, iTmp As String
Dim oStream, iStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtOrg = fso.GetFile("X:\programming\genericER.txt")
Set txtNew = fso.GetFile("X:\programming\test.txt")
Set iStream = txtOrg.OpenAsTextStream(1)
Set oStream = txtNew.OpenAsTextStream(8)
Do While Not iStream.AtEndOfStream
iTmp = iStream.readall ' readall or readline ?
mf1 = Replace(iTmp, "[MAGAZINENAME]", UCase(txtMagName.Text), , 1)
mf2 = Replace(iTmp, "[MAGAZINETYPE]", txtMagType.Text), , 1)
oStream.write mf1 ' write or writeline ?
Loop

i am stuck i tired a few different variants of this.

thnx
__________________
Beyond Limitation
Reply With Quote
  #2 (permalink)  
Old 06-30-03, 22:56
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Re: FSO - Appending Replacements

Quote:
Originally posted by vextout
i am trying to read in a text file and replace certain words and write tit to a new text file. The problem im getting is how to append all the replacements. I tried readall and readline. I have to replace around 10 words. This is what i go so far

mf1 mf2 mf3 are all dim as string
Dim fso, txtOrg, txtNew
Dim oTmp As String, iTmp As String
Dim oStream, iStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtOrg = fso.GetFile("X:\programming\genericER.txt")
Set txtNew = fso.GetFile("X:\programming\test.txt")
Set iStream = txtOrg.OpenAsTextStream(1)
Set oStream = txtNew.OpenAsTextStream(8)
Do While Not iStream.AtEndOfStream
iTmp = iStream.readall ' readall or readline ?
mf1 = Replace(iTmp, "[MAGAZINENAME]", UCase(txtMagName.Text), , 1)
mf2 = Replace(iTmp, "[MAGAZINETYPE]", txtMagType.Text), , 1)
oStream.write mf1 ' write or writeline ?
Loop

i am stuck i tired a few different variants of this.

thnx
I think I understand your need... I would do it this way...

Dim fso, f1, ts, s
Const ForReading = 1
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("c:\test.txt", ForReading)
s = ""
Do While Not ts.AtEndOfStream
s = s & ts.ReadLine
Loop
ts.Close
Set ts = Nothing
Set ts = fso.OpenTextFile("c:\test.txt", ForWriting)
s = Replace(s, "[MAGAZINENAME]", UCase(txtMagName.Text))
s = Replace(s, "[MAGAZINETYPE]", UCase(txtMagType.Text))
ts.Write s
ts.Close
Set ts = Nothing

I wrote this up from my head. I think it will work... you may have to add a parameter in the fso statement depending on the type of file format you're working with. Hope this helps...

Tim
__________________
Tim
Reply With Quote
  #3 (permalink)  
Old 06-30-03, 23:07
vextout vextout is offline
Registered User
 
Join Date: Jan 2003
Location: New York
Posts: 160
i am sorry i forgot to reply to this thread. i got ti wokring middle of last week.

i jsut did it like this.

Do While Not iStream.AtEndOfStream
mf = ""
iTmp = iStream.readline
If InStr(iTmp, "[MAGAZINENAME]") And mf = "" Then
mf = Replace(iTmp, "[MAGAZINENAME]", txtMagName.Text, , 1)
ElseIf InStr(iTmp, "[MAGAZINENAME]") Then
mf = Replace(mf, "[MAGAZINENAME]", txtMagName.Text, , 1)
End If
If InStr(iTmp, "[MAGAZINETYPE]") And mf = "" Then
mf = Replace(iTmp, "[MAGAZINETYPE]", txtMagType.Text, , 1)
ElseIf InStr(iTmp, "[MAGAZINETYPE]") Then
mf = Replace(mf, "[MAGAZINETYPE]", txtMagType.Text, , 1)
End If

and so on for another 10 if statments - it work


thx for reply though
sorry again
__________________
Beyond Limitation
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On