NBee
asked on
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?
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?
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
----- 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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11516478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11529339
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11585158
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11697479
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11744478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11766758
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11818478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11905339
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11938458
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20003831
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20038010
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20127372
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20135883
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20136023
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20142078
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20142830
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20143154
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20144259
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20144370
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20148973
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20150132
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20153238
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20160626
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20162000
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163157
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163242
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163142
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163674
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20165141
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174284
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20184042
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20242564
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20242585
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20252565
https://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
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.
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11516478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11529339
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11585158
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11697479
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11744478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11766758
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11818478
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11905339
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11938458
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20003831
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20038010
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20127372
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20135883
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20136023
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20142078
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20142830
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20143154
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20144259
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20144370
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20148973
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20150132
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20153238
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20160626
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20162000
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163157
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163178
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163242
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163142
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20163674
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20165141
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20174284
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20184042
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20242564
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20242585
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20252565
https://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
Admin notified of user neglect. Force/accepted by
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange
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.