Solved

RTF preview and RTF save of generated document.

Posted on 2000-04-10
10
827 Views
Last Modified: 2012-08-13
I have defined simple language to allow users to create simple letters and then print them out.
A sample program is shown below.
BEGIN-LETTER
SETFONT BOLD
SETJUSTIFY LEFT
PRINT "Dear Mr. "
PRINT-FROM-DATABASE Name
NEWLINE
SETFONT "COURIER NORMAL"
PRINT "You owe us $"
PRINT-FROM-DATABASE owedAmount
NEWLINE
END-LETTER

During Interpretation i simplly use appropriate printer/word/SQL SELECT commands to format the text ....
This produces
---------------
Dear Mr. John
You owe us $100
---------------
This program is stored in SQL SERVER and whenever a letter is to be printed the program is retrieved and interpreted.
I am providing options to print this output to Printer or Word/RTF File.
I guess I can use the printer and word controls to do this.
What I want is a way to preview the generated document before opening it in word or sending it to printer.
I want to be able to preview the document as it is generated in a rich text box. How do I do this ?
Also I want to save the output of the interpreted program as an RTF file.... How do I do this ?

Note that only simple formatting commands (supported by RTF is implemented)
0
Comment
Question by:tellis070898
  • 4
  • 3
  • 2
  • +1
10 Comments
 

Author Comment

by:tellis070898
ID: 2699777
I feel it all boils down to how to dynamically add pieces of differently formatted text to a Rich Text Box during runtime.
Ex. I want to add "Dear John" in bold followed by "You Owe Us" in italics to the rich text box.Is this possible ?
If not can i write these pieces of text to the rich text box and then programatically select the desired portions and apply formatting to them ?
If the above is not possible then, Is it possible to genetate a temp RTF file with the above text and then load this into the rich textbox ?
If none of this is possible how do I go about it ?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2699853
First check out the following microsoft KB  articles:


HOWTO: Set Up the RichTextBox Control for WYSIWYG Printing
http://support.microsoft.com/support/kb/articles/Q146/0/22.asp?LNG=ENG&SA=MSDN&FR=0

HOWTO: Use a PictureBox to Control Orientation Printing a Form
http://support.microsoft.com/support/kb/articles/Q178/0/76.ASP?LNG=ENG&SA=MSDN&FR=0


As for formatting text in a richtextbox, set the "SelStart" property to be the position where you want to start formatting and the "SelLength" property to be the length of the text you want to format.

Then you can use:

   RichTextBox1.SelBold = True

or
   RichTextBox1.SelItalic = True

Or any of the other formatting properties.

You can also use the RichTextBox.Find method to highlight text in the RichTextBox and then use the formatting properties on the highlighted text.


Hope this help!


Cheers!®©
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2700783
richtextbox has a save command built in:
richtextbox.SaveFile(pathname, filetype)
where filetype can be either rtfRTF or rtfText.  It saves as rtfRTF by default.  If you are talking about print preview check out this project example
http://www.vb-helper.com/Howto/prevrtf.zip

also more general info about the richtextbox:
http://www.vbweb.co.uk/controls/rich_text_box.htm

0
 
LVL 5

Expert Comment

by:Voodooman
ID: 2701021
Hi!

I have worked on a Project where I did exactly this.

We saved the Text in a letters table in SQL Server as RTFText with <<Amount Owed>> in the text. These are prompts or fillers - like old fashioned report generators.

For Instance you put in //LastName// to insert a field and <<Amount Owed>> for a user prompt.

Get the Text from your database and set MyRTFbox.textrtf= rs("Text") - as an example.

Then scan the text and fill the fields //LastName// etc.

Now when the user clicks 'Print' scan for prompts and ask the user to fill in <<Amount Owed>>.

You can interpret the <<Amount Owed>> as compulsary and <<<Amount Owe>>> as non compulsary as an example. (Extra braces).

I then made a letter generator where a user could create letters and embed them in the database by setting rs("Text")=myRTF.RTFText so giving access to 300 users as soon as a new letter was available.


Good Luck

Voodooman!
0
 

Author Comment

by:tellis070898
ID: 2703281
Adjusted points from 100 to 150
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:tellis070898
ID: 2703282
Hi the responses were great ...
Mcrider has given me just the solution I need and the links provided by AzraSound were helpful.
I have just a few questions to help me wind up this question ...
# How do I append text into the rich text box ?
# Programaically how do I insert an Image into the rich text box.
# How do I programatically insert newlines and NEWPAGE into the rich text box.

Ex: I have 3 string variables A B and C and an image x.bmp
I want to write A into the rich text box.
Then i want to add B to the box in a new line.
Then I want to add string C in a new logical page (such that the rtf document will have a new page)
Finally I want to insert the image into the text box ...
How do i go about this ?
0
 
LVL 14

Accepted Solution

by:
mcrider earned 150 total points
ID: 2703796
# How do I append text into the rich text box ?

If you do this, you will append text to a richtextbox:

   Dim MyBuffer As String
   MyBuffer = "Here's some more text"
   RichTextBox1.Text = RichTextBox1.Text & MyBuffer




# Programaically how do I insert an Image into the rich text box.

You have to put the image onto the clipboard and then paste it into the richtextbox... Like this:

    Clipboard.Clear
    Clipboard.SetData Picture1.Image, vbCFBitmap
    RichTextBox1.SetFocus
    SendKeys "^v", True




# How do I programatically insert newlines and NEWPAGE into the rich text box.


You can insert new lines by using the "VbCrLf" variable... For example, this will insert a new line at the beginning of the richtextbox:

   RichTextBox1.SelStart = 0
   RichTextBox1.SelLength = 0
   RichTextBox1.SelText = vbCrLf

Unfortunately, the RichTextBox control does NOT support pagebreaks, so if you are printing using the control, you're out of luck...  However, if you are going to be printing from WORD, once you have saved the richtext file using:

   richtextbox1.SaveFile "c:\windows\desktop\testdoc.rtf"

You can open the file as a simple text file using the Open statement and insert the Rich Text Tag "\page " wherever you want a page break (dont use the quotes...)

For example, here is a richtext file that has a page break:

{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\froman\fprq2 Times New Roman;}}
{\colortbl\red0\green0\blue0;}
\deflang1033\pard\plain\f2\fs20 This is a test
\par testing page 1
\par \page this is only a test page 2
\par
\par }




This should deserve an "A"... ;-)



Cheers!®©


0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2704289
if you wanted to pass a new line before appending the new string:

Richtextbox1 = Richtextbox1 & vbCrLf & "My String to Add"

Obviously you can use as many vbCrLf's as you need to put in as many lines as you desire
0
 

Author Comment

by:tellis070898
ID: 2706763
Hi, Mcriders excellent comments answers solve all my problems so an 'A' it will be :-)
AzraSound and Voodooman thanks for the helpful comments and links...
It was a great discussion - Thanks Guys



0
 
LVL 14

Expert Comment

by:mcrider
ID: 2710446
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now