-
This is my code to cause my chat window to scroll down one line to be ready for the next SendData.
It is supposed to resemble your standard run of the mill chat window, but I continue to fail in successful implementing an AUTO SCROLLING feature.
I would sure appreciate it if you could help me out...
Here is the error I am getting:
"Runtime error #28, Out of stack space"
When I hit Debug I am brought to this Sub:
Code:
Private Sub Chat_Change()
Chat.Text = Chat.Text & vbNewLine
'See if auto-scroll is desired
If chkScroll.Value = 1 Then
'Start the Auto Scroll
Chat.SelStart = Len(Chat.Text)
End If
End Sub
The highlighted offending line is:
Chat.Text = Chat.Text & vbNewLine
-
Out of stack space means, that there are two much functions/subs called at the same time.
This line:
Code:
Chat.SelStart = Len(Chat.Text)
Will raise another Chat_Change event. So, it results in endless-looping.
-
Declare a boolean var, wrap the entire code in the sub in an if statement that only enters the if when the boolean var is true. In the first line of the if statement, set the boolean to True, and set it to false at the end of the code inside the if. That way, when the change event is called, it only executes your code if it is not already changing.
I'd write some code, but I'm in a rush. Sorry
- gaffa
-
Thanks for the reply...
Thanks guys, much appreciated...
-
Gaffa
Gaffa is this what you mean....if so, it is failing to auto scroll.
Code:
Private Sub Chat_Change()
Dim TextChange As Boolean
If TextChange = True Then
Chat.Text = Chat.Text & vbNewLine
'Auto Scroll
Chat.SelStart = Len(Chat.Text)
TextChange = False
End If
End Sub
This auto scrolling and making the text box automatically move down one line is very nerve racking, (That and I'm on the tired side):-)
-
-
Just remove the line: Chat.Text = Chat.Text & vbNewLine ...
The rest of the code will allow for the autoscroll like a dos window/telnet window/mirc, etc. I've done this before and it works. Basically, you want it so the text scrolls up like you're constantly at the last line (not a blank line, unless someone sends an enter)? Then the code that oetje gave you will work perfectly.
-
Perfect, I appreciate the tip.
-
I predict a problem with your code (I might be wrong).
The boolean should be Static...
Code:
Private Sub Chat_Change()
Static TextChange as Boolean
If TextChange = True Then
Chat.Text = Chat.Text & vbNewLine
'Auto Scroll
Chat.SelStart = Len(Chat.Text)
TextChange = False
End If
End Sub
Or Global...
Code:
Option Explicit
Private TextChange as Boolean
Private Sub Chat_Change()
If TextChange = True Then
Chat.Text = Chat.Text & vbNewLine
'Auto Scroll
Chat.SelStart = Len(Chat.Text)
TextChange = False
End If
End Sub
ExcalibursZone is also right. However, if you take the line
Code:
Chat.Text = Chat.Text & vbNewLine
out, you will have to add a line break before adding the next person's chat text.
-
And naturally, I want to have the code force a line break.
I appreciate your reply.