RTF Report

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?
NBeeAsked:
Who is Participating?
 
wileecoyCommented:
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
 
inthedarkCommented:
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
 
wileecoyCommented:
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
 
NetminderCommented:
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
 
NetminderCommented:
Admin notified of user neglect. Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.