Solved

Stupid VB RichTextBox question???

Posted on 2001-06-07
5
154 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

688 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