Solved

Stupid VB RichTextBox question???

Posted on 2001-06-07
5
150 Views
Last Modified: 2010-05-02
I am writing a small program to display a data file on a machine.  The file is updated frequently so I am refreshing the file by loading it every 30 seconds in a richtextbox.  I need to have the text box automatically scroll to the bottom every time it loads so the user can see what data was added. Can anyone help me out with how to do that?  thanks,

 
0
Comment
Question by:halfback71
5 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6164976
txtbox.selstart = len(txtbox.text)
0
 
LVL 7

Accepted Solution

by:
q2eddie earned 200 total points
ID: 6164977
Hi, halfback71.

#Try This
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SetFocus

Bye. -e2
0
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6164978
Try

  RichTextBox1.SelStart = Len(RichTextBox1.Text)
  RichTextBox1.SelLength = 0
  RichTextBox1.Refresh

This will move the cursor to the bottom of the rich text box.
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6164997
build of this code


Private Type SCROLLINFO
    cbSize As Long
    fMask As Long
    nMin As Long
    nMax As Long
    nPage As Long
    nPos As Long
    nTrackPos As Long
End Type
Private Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Const SIF_RANGE = &H1
Const SB_VERT = 1

Dim lHeight As Long, OnePixel As Long
Dim S As SCROLLINFO

Private Sub ScrollUp(delay As Long)
  Sleep delay
  With rtb1(0)
   .Top = .Top - OnePixel
   If .Top + .Height = 0 Then
      .Move 0, 0
      rtb1(1).Visible = False
   End If
   If .Top + .Height <= Picture1.Height Then
      rtb1(1).Top = .Top + .Height
      rtb1(1).Visible = True
   End If
  End With
End Sub

Private Sub Form_Load()
'CHANGE TO YOUR OWN FILE NAME
 rtb1(0).LoadFile App.Path & "\mydoc.rtf", rtfRTF
 Picture1.Move rtb1(0).Left, rtb1(0).Top, rtb1(0).Width, rtb1(0).Height
 Set rtb1(0).Container = Picture1
 OnePixel = Screen.TwipsPerPixelY
 S.cbSize = Len(S)
 S.fMask = SIF_RANGE
 Do
   Call GetScrollInfo(rtb1(0).hwnd, SB_VERT, S)
   If S.nMax = 0 Then Exit Do
   lHeight = S.nMax * OnePixel
   rtb1(0).Height = lHeight
 Loop
 If lHeight = 0 Then lHeight = rtb1(0).Height
 Text1 = lHeight / OnePixel
 rtb1(0).Move 0, 0
 Load rtb1(1)
 rtb1(1).Visible = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
  End
End Sub

'Using
'Private Sub Command1_Click()
'  Do
'    DoEvents
'    ScrollUp 50
'  Loop
'End Sub
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6165133
if you want to know how to make it so that it re-loads the file every 30 seconds do this:

put a timer on your form and set the interval to 3000 (30 seconds)

then put this code in your form module.

private sub timer1_timer()

    richtextbox1.loadfile "<path to file>"
    richtextbox1.selstart = len(txtbox.text)
    richtextbox1.setfocus
 
end sub

good luck
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

706 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

16 Experts available now in Live!

Get 1:1 Help Now