Solved

Stupid VB RichTextBox question???

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…

772 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