|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Write text to File with templateHello,
I have some template text file. I need write more text files, that contains text from template and have fill in other text (for example adress). In MS Word it is "Correspondence". Can you help me, haw can I write it in VB? Thank You OndrejD On Thu, 2 Jul 2009 01:11:01 -0700, OndrejD
<Ondr***@discussions.microsoft.com> wrote: >Hello, Q&D, but you should get the idea.>I have some template text file. >I need write more text files, that contains text from template and have fill >in other text (for example adress). >In MS Word it is "Correspondence". >Can you help me, haw can I write it in VB? Template: Name : {name} Address : {address} etc ... Get the template data : F = FreeFile Open "Template.dat" For Binary As #F Buff = Space$(Lof(F)) Get#F, 1, Buff Close #F Populate the template : If Instr(Buff, "{name}") <> 0 Then Buff = Replace$(Buff, "{name}", mName) End If If Instr(Buff, "{address}") <> 0 Then Buff = Replace$(Buff, "{address}", mAddress) End If etc ... Display: txtOutput.Text = Buff You can extend the logic to use an RTB or HTML. If you're talking about using Word files, that's an entirely different animal, although the concept may still apply. Essentially, you define tokens that have a specific meaning (eg.: {name}), and then replace the occurrences of the tokens with their actual values. I personally tend to use {} to wrap my tokens, because they are seldom used in the wild, reducing the possibility of a literal being interpreted as a token. I can explain better if necessary, but I'm still on my first coffee .... ugh. >Thank You HTH,>OndrejD J. Jeremiah D. Seitz Omega Techware http://www.omegatechware.net
Removing too many hyphens
Printing contents of a picture box Package & Deployment Perplexing Problem - Need Help Copy & Move files Remote-Desktop "client/ server" Re: ADO: Deleting a table after it is loaded into Recordset Date and regional settings problem Type comparison Problem with DIR function..... |
|||||||||||||||||||||||