Solved

RTF Report

Posted on 2001-07-30
5
260 Views
Last Modified: 2010-05-02
Hi all,
I write a VB program to report in form of .RTF file.
I have a RTF template file with the structure that I define, such as:

MONTHLY REPORT
1. <ITEM>

I will read in database to generate rtf report. I will read in the template file and replace <ITEM> with the data I have. It works fine, but when I want to generate a tree form, such as

MONTHLY REPORT
1. 30/11/2000
   Fish
       - A     : 10Kg
       - B     : 1Kg
   Gas
       - D     : ...
2. 31/12/200
   ABC
       - A     :...

The items are dynamic, not fix. How can I do that?
0
Comment
Question by:NBee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 6337078
You should be able to keep adding to the end of your RTF file.

So you you need to identify the code you need for each of the indentation levels and just append this to the end of the template.

Create a shortcut for Notepad on your desktop and you can drag & drop a sample RTF file onto the ICON and then see what RTF codes are being used.
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6337671
I created a new standard exe and added the RichTextBox component and added it to Form1 as RichTextBox1.

----- code -----

Private Sub Form_Load()
    RichTextBox1.Text = "Item 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(2) & "sub 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub1" & Space(4) & ": Other 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub1" & Space(4) & ": Other 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(2) & "sub 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub2" & Space(4) & ": Other 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub2" & Space(4) & ": Other 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(2) & "sub 3"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub3" & Space(4) & ": Other 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub3" & Space(4) & ": Other 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & "Item 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(2) & "sub 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub1" & Space(4) & ": Other 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub1" & Space(4) & ": Other 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(2) & "sub 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub2" & Space(4) & ": Other 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub2" & Space(4) & ": Other 2"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(2) & "sub 3"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub3" & Space(4) & ": Other 1"
    RichTextBox1.Text = RichTextBox1.Text & Chr(10) & Space(4) & "- doubleSub3" & Space(4) & ": Other 2"
End Sub

----- end code -----

The above code shows how to format in a simple way.  However, you won't want to do that if you are reading from a database.

You will want to create a procedure that programatically does it.

for example:

----- code -----

Private Sub Form_Load()
    PopulateRTF
End Sub

Private Sub PopulateRTF()
    Dim i As Integer
    Dim ii As Integer
    Dim iii As Integer
    Dim MyString As String
   
    MyString = "My Report"
    For i = 1 To 3          'This would actualy be the # of <ITEM> records in your database.
        MyString = MyString & Chr(10) & "Item " & i  'Replace "Item 2" with your <ITEM> database
        For ii = 1 To 3     'This would be the sub item collection that relates to <ITEM>
            MyString = MyString & Chr(10) & Space(6) & "sub " & i & "." & ii
            For iii = 1 To 2
            MyString = MyString & Chr(10) & vbTab & "- doubleSub" & ii & Space(4) & ": Other " & iii
            Next iii
        Next ii
    Next i
   
    RichTextBox1.Text = MyString
End Sub

----- end code -----

As you can see, I am creating the information to put into the text for example purposes.

hth
0
 
LVL 4

Accepted Solution

by:
wileecoy earned 100 total points
ID: 6337709
I forgot about the most important part.  The save.

RichTextBox1.SaveFile "C:\MyReport.rtf", 0

The '0' at the end indicates that the file is to be saved in the rtf format instead of text format.

hth.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6764275
NBee,

The following questions are open, and have been open for some time. Further, your profile indicates you logged in as recently as Jan 29, 2002. Please resolve them within the next seven (7) days; following that period of time, I or one of the other Moderators will take action to close this question. Additionally, this list has been forwarded to Administration; please expect an email from them regarding your account's status.

http://www.experts-exchange.com/jsp/qShow.jsp?qid=11516478
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11529339
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11585158
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11697479
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11744478
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11766758
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11818478
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11905339
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11938458
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20003831
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20038010
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20127372
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20135883
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20136023
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20142078
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20142830
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20143154
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20144259
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20144370
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20148973
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20150132
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20153238
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20160626
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20162000
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163157
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163178
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163242
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163142
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20163674
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20165141
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20174284
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20184042
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20242564
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20242585
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20252565
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20259368

Further, you should note that the guidelines for questions suggest that an "Easy" question is worth 50 points.

Thank you for your attention to the above questions.

Netminder
Community Support Moderator
Experts Exchange
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6804084
Admin notified of user neglect. Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

617 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