Solved

Scrollbar and RTF

Posted on 1998-09-15
7
813 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
ID: 1435068
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
ID: 1435069
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
ID: 1435070
Change your line RTF1.Text to RTF1.TextRTF and change the property "Scrollbars" on your RTFbox to "both"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:DAVIDH
ID: 1435071
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
ID: 1435072
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
ID: 1435073
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
ID: 1435074
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

947 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

23 Experts available now in Live!

Get 1:1 Help Now