Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Control scrolling in a TextBox


I am using a TextBox with a vertical scrollbar as a message area where
messages are accumulated over time as the user does things. Each
message is appended to the previous with a chr(10) in VBA. This keeps
a history of user changes available. Multiline is true.

Problem is, the TextBox seems by default to show the top, or first,
row of information rather than the bottom, most recent information. So
lines are added, but it isn’t visible to the user. Only when I click
in the box it switches to the last line.

What I want is to always be showing the last, most recent line, all
the time, unless the user scrolls up.

Is it possible to create that behavior somehow?

Thanks
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Control scrolling in a TextBox

On Sep 18, 9:41*am, "Nigel" wrote:
Add the new text into the box by appending at the top?

TextBox.Value = "New Message" & vbCrLf & TextBox.Value

instead of

TextBox.Value = *TextBox.Value & vbCrLf & "New Message"

--
Regards,
Nigel


"Revolvr" wrote in message

...

I am using a TextBox with a vertical scrollbar as a message area where
messages are accumulated over time as the user does things. Each
message is appended to the previous with a chr(10) in VBA. This keeps
a history of user changes available. Multiline is true.

Problem is, the TextBox seems by default to show the top, or first,
row of information rather than the bottom, most recent information. So
lines are added, but it isn’t visible to the user. Only when I click
in the box it switches to the last line.

What I want is to always be showing the last, most recent line, all
the time, unless the user scrolls up.

Is it possible to create that behavior somehow?

Thanks



I can try this. But what I am seeing is the scroll bar seems to
position itself neither at the top, nor at the bottom. It seems to
park a few lines from the bottom. Is there direct control over where
it scrolls to?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Control scrolling in a TextBox

On Sep 18, 12:31*pm, Revolvr wrote:
I am using a TextBox with a vertical scrollbar as a message area where
messages are accumulated over time as the user does things. Each
message is appended to the previous with a chr(10) in VBA. This keeps
a history of user changes available. Multiline is true.

Problem is, the TextBox seems by default to show the top, or first,
row of information rather than the bottom, most recent information. So
lines are added, but it isn’t visible to the user. Only when I click
in the box it switches to the last line.

What I want is to always be showing the last, most recent line, all
the time, unless the user scrolls up.

Is it possible to create that behavior somehow?

Thanks


Maybe the following code snippet will help:

Private Sub btnPress_Click()
Dim s As String
s = InputBox("Enter message")
TextBox1.Text = TextBox1.Text & vbCrLf & s
TextBox1.SetFocus
TextBox1.CurLine = TextBox1.LineCount - 1
btnPress.SetFocus
End Sub


-scattered
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Control scrolling in a TextBox

I am using a TextBox with a vertical scrollbar as a message area where
messages are accumulated over time as the user does things. Each
message is appended to the previous with a chr(10) in VBA. This keeps
a history of user changes available. Multiline is true.

Problem is, the TextBox seems by default to show the top, or first,
row of information rather than the bottom, most recent information. So
lines are added, but it isn’t visible to the user. Only when I click
in the box it switches to the last line.

What I want is to always be showing the last, most recent line, all
the time, unless the user scrolls up.

Is it possible to create that behavior somehow?

Thanks


Maybe the following code snippet will help:

Private Sub btnPress_Click()
Dim s As String
s = InputBox("Enter message")
TextBox1.Text = TextBox1.Text & vbCrLf & s
TextBox1.SetFocus
TextBox1.CurLine = TextBox1.LineCount - 1
btnPress.SetFocus
End Sub


I would suggest you issue this statement immediately after the CurLine
assignment so the caret (text cursor) is in the more normal position at the
end of the newly added text...

TextBox1.SelStart = Len(TextBox1.Text)

I would also note the this section of the (now modified) code...

.....
.....
TextBox1.SetFocus
TextBox1.CurLine = TextBox1.LineCount - 1
TextBox1.SelStart = Len(TextBox1.Text)
btnPress.SetFocus

could be replaced with this...

.....
.....
TextBox1.SetFocus
SendKeys "^{END}"
btnPress.SetFocus

--
Rick (MVP - Excel)



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Control scrolling in a TextBox


Thanks for the help so far, but something isn't right.

When I use TextBox1.SelStart = Len(TextBox1.Text)
I get a compile error "Invalid use of property"
I cannot get the LineCount because it says control needs to have focus
first, however, when I use TextBox1.SetFocus I get a run time error
that says "Object doesn't support this property or method".

If it helps, this is Excel 2003.

Any ideas?
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Control scrolling in a TextBox

On Sep 18, 6:16*pm, Revolvr wrote:
Thanks for the help so far, but something isn't right.

When I use TextBox1.SelStart = Len(TextBox1.Text)
I get a compile error "Invalid use of property"
I cannot get the LineCount because it says control needs to have focus
first, however, when I use TextBox1.SetFocus I get a run time error
that says "Object doesn't support this property or method".

If it helps, this is Excel 2003.

Any ideas?


The problem is that embedded text boxes work differently from those on
forms. For the embedded ones, "Activate" evidently plays the role of
SetFocus.

In any event, as an experiment I used the control toolbox to create an
embedded textbox and an embedded button which I renamed btnPress with
the following click event:


Private Sub btnPress_Click()
Dim s As String
s = InputBox("Enter message")
If TextBox1.Text = "" Then
TextBox1.Text = s
Else
TextBox1.Text = TextBox1.Text & vbCrLf & s
End If
TextBox1.Activate
TextBox1.CurLine = TextBox1.LineCount - 1
TextBox1.SelStart = Len(TextBox1.Text)
End Sub

(This incorporates Rick's excellent suggestion which leaves the cursor
at the end of the input - you can activate or select something else
afterwards of course)

This seems to work - just keep hitting button press and adding data.
The bottom row is always visible

hth

-scattered
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Control scrolling in a TextBox

On Sep 19, 6:43*am, scattered wrote:
On Sep 18, 6:16*pm, Revolvr wrote:

Thanks for the help so far, but something isn't right.


When I use TextBox1.SelStart = Len(TextBox1.Text)
I get a compile error "Invalid use of property"
I cannot get the LineCount because it says control needs to have focus
first, however, when I use TextBox1.SetFocus I get a run time error
that says "Object doesn't support this property or method".


If it helps, this is Excel 2003.


Any ideas?


The problem is that embedded text boxes work differently from those on
forms. For the embedded ones, "Activate" evidently plays the role of
SetFocus.

In any event, as an experiment I used the control toolbox to create an
embedded textbox and an embedded button which I renamed btnPress with
the following click event:

Private Sub btnPress_Click()
* * Dim s As String
* * s = InputBox("Enter message")
* * If TextBox1.Text = "" Then
* * * * TextBox1.Text = s
* * Else
* * * * TextBox1.Text = TextBox1.Text & vbCrLf & s
* * End If
* * TextBox1.Activate
* * TextBox1.CurLine = TextBox1.LineCount - 1
* * TextBox1.SelStart = Len(TextBox1.Text)
End Sub

(This incorporates Rick's excellent suggestion which leaves the cursor
at the end of the input - you can activate or select something else
afterwards of course)

This seems to work - just keep hitting button press and adding data.
The bottom row is always visible

hth

-scattered



That's it! Of course, Instead of using SetFocus to set focus, use
Activate, if it's an embedded text box. I would not have guessed. That
solved it. Thanks.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
scrolling textbox Shawn G. Excel Programming 1 September 12th 06 07:01 PM
How to move cursor from one textbox control to another textbox con Tom Ogilvy Excel Programming 1 September 16th 04 03:42 PM
How to move cursor from one textbox control to another textbox con KMoore007 Excel Programming 0 September 16th 04 02:47 PM
Set Focus Problem for textbox control on multipage control ExcelDeveloperSPR Excel Programming 1 July 16th 04 08:54 PM
Scrolling TextBox...? Robert Stober Excel Programming 2 October 14th 03 09:24 AM


All times are GMT +1. The time now is 08:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"