Solved

Scrollbar and RTF

Posted on 1998-09-15
7
811 Views
Last Modified: 2012-06-21
This is my goal:

Insert a rtf document in a text box and use the scrollbar to navigate to the bottom of the document.  When I inserted the contents of the rft into the richtextbox I get jibberish such as /tab/format/printrange/   filling up the entire richtextbox.

so I changed to OLE.  My question is:

A: Can I do this without OLE. and if so I need to know how to take a 15 page RTF document and add it to the Richtextbox (or other control) and scroll up and down it.
(I still don't know how to use the scroll bar, I need code)

B: if I must use OLE, How do I set the scrollbar so It moves the document?

If I am unclear, post a msg I will clarify.
Thanks
 
0
Comment
Question by:DAVIDH
  • 3
  • 3
7 Comments
 
LVL 2

Expert Comment

by:cantrell
Comment Utility
Read your information in and put the text into the rtf window. Make sure you:

Put the text into the window with rtfWindow.text (without that you will get the rtf jibberish).

Set the property on the rtf box's "DisableNoScroll" to "False" - That should give you the scroll bar if the text is longer than the window.
0
 

Author Comment

by:DAVIDH
Comment Utility
Thank you for your help, but I need some detail:

1st:  what is RTFwindow.text?

2nd:  I have never used the scroll bar.  I will need horizontal and vertical.  How do I tie the scroll bars to the RTF conrol?

Here is the code I am using to put the document into the textbox:

Open ("c:\windows\desktop\apps.rtf") For Binary Access Read As #1
RTF1.Text = Input(LOF(1), 1)
Close #1


Thanks!
0
 
LVL 2

Expert Comment

by:cantrell
Comment Utility
Change your line RTF1.Text to RTF1.TextRTF and change the property "Scrollbars" on your RTFbox to "both"
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:DAVIDH
Comment Utility
Your Answer is correct, but It doesn't solve my problem.  I need the contents of the text file to be perminently in the text box.  If the this program is on a different computer, but the file is not, the box should still show the information.  Do I need to use OLE for this?  If so how do I use a scroll bar for this?

Also, when I used the RTF control it works except even though i put both for the scroll bars, it only shows verticle and distorts the data since the document is wider than the box.

If I can solve these problems, I will award the points.

thanks
0
 
LVL 2

Expert Comment

by:cantrell
Comment Utility
I'm a little confused. If the program is on a different computer, but the file is not, you can't open it, unless it's on a networked computer that you have access to.


0
 
LVL 12

Accepted Solution

by:
mark2150 earned 60 total points
Comment Utility
You can set a file as the properties of the RTF box. You should also set the right margin property to somthing under the width of the RTF box. This will enable word wrap and keep your document looking nice.

Load the "static" text into the RTF box at design time. This will be carried with the box and will apear no matter if the remote file is accessable or not.

Here is a code snippet that will clear the box and load a file if it is available. The RTF box is called NOTES in this example

notes.Text = ""
notes.TextRTF = ""
'
RTFFile = homedrive + "\" + filename + ".rtf"
On Error GoTo nofile
FileLen (RTFFile)               'Traps out if file doesn't exist
notes.LoadFile RTFFile, rtfRTF  'Get file contents
GoTo drain                      'Skip trap
' =================
'
' Here if file doesn't exist - skip load
'
nofile:
Resume drain
' = = = = = = = = = No real fallthru
'
drain:
On Error GoTo 0                 'Turn off trapping
notes.RightMargin = notes.Width 'Non zero margin required for .selAlignment to work!

If you want to *PRINT* your document try:

Private Sub btn_print_Click()
If Not armprinter Then GoTo drain
'
' Select all text and then apply margins to it prior to printing.
'
notes.SelStart = 0
notes.SelLength = Len(notes.Text)
notes.Visible = False
notes.SelIndent = Int(0.75 * TpI + 0.5)
notes.SelRightIndent = Int(0.75 * TpI + 0.5)
'
Printer.Print ""    'This is required to initialize the .hDC needed in next line
notes.SelPrint (Printer.hDC)
On Error Resume Next    'Ignore error if Adobe
Printer.EndDoc
On Error GoTo 0
'
notes.SelIndent = 0
notes.SelRightIndent = 0
notes.SelLength = 0
notes.Visible = True
'
drain:
'
End Sub

the ARMPRINTER function is:

Public Function armprinter() As Boolean
'
' This function is used to determine if printing is required
' The big savings is that any form can call us and that
' particular form doesn't need a COMMONDIALOG object locally
' to determine if printing is switched on. This function returns
' a logical:
'
'   TRUE - Print
'   FALSE - Cancel
'
' Thus the caller can simply use:
'
'   if not armprinter then goto {abort label}
'
' Pretty slick, eh?
'
armprinter = True
On Error GoTo trapped
CommonDialog1.Flags = 0
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
'
' We make it here then user said OK to print, pass default
' value back
'
GoTo drain
' =================
'
' Here on error trap of [Cancel], pass falsity back
'
trapped:
armprinter = False
Resume drain
' = = = = = = No fallthru
'
drain:
End Function

I have a complete form that loads, saves, and allows editing of RTF objects. With it you can change the font, color, alignment, as well as being able to set bold/italic/underline.

Drop me a line at mark_lambert@ntsc.navy.mil if you want the code.

0
 

Author Comment

by:DAVIDH
Comment Utility
Thank you,

My email is Dhill10358@aol.com.  Please send me the source code you mentioned.  I would be most appreciative!

Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

728 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

11 Experts available now in Live!

Get 1:1 Help Now