Solved

RTF Report

Posted on 2001-07-30
5
250 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
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:inthedark
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Admin notified of user neglect. Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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

7 Experts available now in Live!

Get 1:1 Help Now