Solved

Text Box with scroll property

Posted on 2000-05-01
6
252 Views
Last Modified: 2010-05-02
Looking for a control that will display text and have an scroll bar property that will allow it to move at run time. Basically I need to view text as it is being written in a text box. On a standard text box, when it writes more than can be displayed I have to scroll to see the current line being written.  I need a way to either advance the scroll bar with code as lines are being written or find another way to write so that the most recent line is always  visible.
0
Comment
Question by:liberty6
  • 3
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
StingRaY earned 50 total points
ID: 2768136
Try This:

Private Sub Text1_Change()
    Text1.SelStart = Len(Text1.Text)
End Sub
0
 
LVL 1

Expert Comment

by:4P
ID: 2768163
I just tried it with VB 6, if you set the scrollbars property to vertical (and of course set the multiline to true) for your textbox then it does make the cursor position visible.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2768170
how is the textbox being written to?  stingray provides an answer except if the user tries to delete some characters that are, say, in the previous line, after hitting the backspace once it will advance the cursor to the end of the text.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2768173
thats why i ask about how it is being written to the textbox b/c the textbox automatically scrolls so i assume the questioner must be doing something out of the ordinary for it not to be scrolling.
0
 
LVL 15

Expert Comment

by:StingRaY
ID: 2768274
Well, If you want to identify current line your cursor is, try this code:

First Set Your Form.KeyPreview = True
and Put this code it to your form

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  If ActiveControl.Name = "Text1" Then
    If (KeyCode = vbKeyLeft) Or (KeyCode = vbKeyRight) Or (KeyCode = vbKeyUp) Or (KeyCode = vbKeyDown) Then
      Label1.Caption = CurLocation
    End If
  End If
End Sub

Private Sub Text1_Change()
  Label1.Caption = CurLocation
End Sub

Private Function CurLocation() As Long
  ' New Line Count
  Dim NewLineCount As Long
  Dim strTemp As String
  Dim pos As Long
 
  NewLineCount = 0
  pos = 1
  strTemp = Left(Text1.Text, Text1.SelStart)
  Debug.Print Text1.SelStart
  pos = InStr(pos, strTemp, vbLf)
  Do Until pos = 0
    NewLineCount = NewLineCount + 1
    pos = pos + 1
    pos = InStr(pos, strTemp, vbLf)
  Loop
  CurLocation = (NewLineCount + 1)
End Function

I think this will help you...
Label1 will display line number that your cursor is...
0
 
LVL 15

Expert Comment

by:StingRaY
ID: 2768276
liberty6:

Anyway , according to my code, I will see I didn't trap Page up and Page down and Arrow key from NumPad.
I just guide you to how-to.

Happy Programming.

StingRaY
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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.
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…
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…

757 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

19 Experts available now in Live!

Get 1:1 Help Now