Private Declare Function SendMessage _
Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Const EM_GETFIRSTVISIBLELINE As Long = &HCE
Private Const EM_LINESCROLL As Long = &HB6
Public Sub SetTopIndex(rtb As RichTextBox, ByVal nLine As Long)
Dim nIndex As Long
nIndex = nLine - SendMessage(rtb.hwnd, EM_GETFIRSTVISIBLELINE, 0&, 0&)
Call SendMessage(rtb.hwnd, EM_LINESCROLL, 0&, ByVal nIndex)
Private Sub Form_Load()
rtb.Text = ""
rtb.SelText = "This is a text, this is only a text test, which is long"
SetTopIndex rtb, 0
In fact, a RichTextBox DOES scroll horizontally, too, for has it not got a horizontal scrollbar option?
But in the end I think this will not provide for the ticker effect you want.
I'd say you have to program it yourself, using a timer control which 'ticks' the text on, by deleting the first character of the vertical oriented RichTextBox and appending the next to it's end.
Coloring is a different story.
I'd do it like this:
Assumed you have a vertical rtb box, arranged like a ticker line.
First fill in as many blanks (or dots) to fill the visible field.
Then you split your original string into an array, splitting by "|"
Then you append each partial string to the rtb, coloring it depending on the occurrence of up or down.
After all strings are appended, you start the timer, which will simply always delete the first character in the rtb, thus advancing the text through the line with the time specified by the timer interval.
If you have problems to implement the algorithm like discribed, please come back for more detailed help.
In fact, come to think of it, scrolling is easier with the scrollbar:
Put a RichTextBox named rtb on a form.
Set its .MultiLine property to false and the .Scrollbar property to rtfHorizontal
Put a Timer Timer1 on your form. Set the interval to 80
The following code fills the rtb with the ticker line, colors it and scrolls it by timer control.
Private Sub Form_Load()
Dim n%, p%
'this only fills in a dummy ticker line. Tick should contain your ticker line to show.
For n = 1 To 10: Tick = Tick + "ABBNK 120 up | BXTX 66 down | CTBNK 800 down | ": Next
'fill the rtb with a set of dots (or spaces) depending on its size, + the ticker string
rtb.Text = String(PreLen, ".") + Tick
'now do the coloring
n = PreLen + 1
rtb.SelStart = n - 1
p = InStr(n, rtb.Text, "|")
If p = 0 Then p = Len(rtb.Text)
rtb.SelLength = p - n
rtb.SelColor = IIf(InStr(rtb.SelText, "up"), vbGreen, vbRed)
n = p + 1
Loop Until p >= Len(rtb.Text)
rtb.SelStart = 0
Private Sub Timer1_Timer()
Also the timer control is rather primitive it works fine.
If necessary the timer can use SendMessage to scroll the rtb forward. Or there is maybe an even better way to emulate the right arrow key.
Correct me if I am wrong but it seems to me that the intention would be to continually scroll this text. In other words when it gets to the end of the data string it begins scrolling the first again.
What I would suggest is to use something similar to post number 3 but rather than delete the first character you would move the first character to the end of the string thereby creating a never ending marquee of this text though I would imagion given the content that these values would also need to be modified at some interval. What was up may be down on the next pass in some cases.