This code is ugly, and quirky, and slow, but I think it does basically what you are wanting to do. The quirkiness comes from the fact that I don't know of a way to set the top line displayed in a text box -- so I used the "SelStart" to set the Selection bar location. Since SelStart defines a character position instead of a line position, I had to process through the text to translate that into lines, which makes the function slow.

Also, if you change the scroll bar, and calculate a new character position that is already displayed within the text box, the text box doesn't scroll at all. This makes it look like the scroll bars aren't working, when in fact, the SelStart value has changed. There may be ways to code around this, but I didn't take the time to figure it out. Does anybody know an easy way to tell if the scroll bar has been moved up or down? The only thing I could think of was to keep current value versus last value and compare them. Yuck.

Vscroll1 is the scroll bar object. The Max property is set to the number of lines in the text boxes. This, combined with a SmallChange property of 1, means that clicking on the scroll bar arrows will scroll the text by one line up or down. The LargeChange property is set to the number of lines displayed in the text boxes, so that clicking on the scroll bar itself results in "page up" and "page down" functionality.

The two text boxes are named txtSource and txtResults. They show 13 lines of text each.

I used the "Vscroll1.Value + 13" in the loop so that when the user first tries to scroll down using the arrows, the text starts moving right away -- they don't have to click on the arrows 13 times first. I tried setting the initial value of Vscroll1.Value to 13, which has the same sort of effect, but that led to a whole different set of quirks.

Needless to say, this looks like it is possible, but not pretty or easy.

Good luck!


VB Code:
  1. Private Sub VScroll1_Change()
  2.  
  3.   CharIndx = 1
  4.   CurLine = 1
  5.  
  6.   If VScroll1.Value <> 1 Then
  7.     Do
  8.       NextChar = Mid(txtSource.Text, CharIndx, 1)
  9.       If NextChar = Chr(13) Then
  10.         CurLine = CurLine + 1
  11.       End If
  12.       CharIndx = CharIndx + 1
  13.     Loop Until NextChar = "" Or CurLine >= (VScroll1.Value + 13)
  14.   End If
  15.   txtSource.SelStart = CharIndx
  16.  
  17.   If txtResults.Enabled = True Then
  18.     CharIndx = 1
  19.     CurLine = 1
  20.  
  21.     If VScroll1.Value <> 1 Then
  22.       Do
  23.         NextChar = Mid(txtResults.Text, CharIndx, 1)
  24.         If NextChar = Chr(13) Then
  25.           CurLine = CurLine + 1
  26.         End If
  27.         CharIndx = CharIndx + 1
  28.       Loop Until NextChar = "" Or CurLine >= (VScroll1.Value + 13)
  29.     End If
  30.     txtResults.SelStart = CharIndx
  31.   End If
  32.  
  33. End Sub