Solved

RTF Report

Posted on 2001-07-30
5
255 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

803 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