Solved

Scrollbar and RTF

Posted on 1998-09-15
7
817 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SLMGR Switches Are Not Working On KMS Host 3 170
Hide vba in gp 7 127
which modules are active in VB6 project? 6 57
Access2016 ignore hyphen in data entry or searches 5 70
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

752 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