I have created a programin Visual basic 6 that views a log file. When the program comes across an alarm or a fault listing in the log file I want to append this data to a richtextbox. I have seen plenty of responses on the net that say use the following code:-
RichTextBox1.appendtext (Text1.Text)
when I run the program I get the following error:-
"Method or data member not found"
Is this method only available for vb.net or am I doing something that is obviously wrong
Appending Text to a Richtextbox
Page 1 of 18 Replies - 22679 Views - Last Post: 01 August 2008 - 10:03 AM
Replies To: Appending Text to a Richtextbox
#2
Re: Appending Text to a Richtextbox
Posted 30 July 2008 - 03:19 AM
That function doesn't exist with VB 6's RTB. If you're looking to append the text, you can do something like this:
RTB.Text = RTB.Text & String & vbNewLine
#3
Re: Appending Text to a Richtextbox
Posted 30 July 2008 - 03:23 AM
Zhalix, on 30 Jul, 2008 - 03:19 AM, said:
That function doesn't exist with VB 6's RTB. If you're looking to append the text, you can do something like this:
RTB.Text = RTB.Text & String & vbNewLine
Thanks for reply - thats what I'm currently doing but if you get a lot of text it slows the program down because all the text has to be rewritten into the box along with the formatting.
#4
Re: Appending Text to a Richtextbox
Posted 30 July 2008 - 04:32 AM
I see.
Have you tried setting the RTB's SelStart at the very end of the text, and then setting the SelText to the appropriate text? Just a guess but I figure it's worth a shot.
Have you tried setting the RTB's SelStart at the very end of the text, and then setting the SelText to the appropriate text? Just a guess but I figure it's worth a shot.
#5
Re: Appending Text to a Richtextbox
Posted 30 July 2008 - 04:58 AM
This is the code I am using to format the colors of the text where required. If I dont reformat the existing text it prints without formatting:-
marcfindita = "!"
marcfinditb = "*"
lengther = Len(marcfindita)
totallength = Len(frmFaultview.RichTextBox1.Text)
start = 0
Do Until start >= totallength
foundpos1 = frmFaultview.RichTextBox1.Find(marcfindita, start, totallength, Text)
If foundpos1 = -1 Then Exit Do
If foundpos1 <> -1 Then 'exclamation mark found
foundpos2 = frmFaultview.RichTextBox1.Find(marcfindita, foundpos1 + 1, totallength, Text)
If foundpos2 = -1 Then Exit Do
If foundpos2 <> -1 Then
frmFaultview.RichTextBox1.SelStart = foundpos1
frmFaultview.RichTextBox1.SelLength = foundpos2 - foundpos1 + 1
frmFaultview.RichTextBox1.SelBold = True
frmFaultview.RichTextBox1.SelColor = RGB(255, 0, 0)
start = foundpos2 + 1 ' start looking here
End If
End If
Loop
lengther = Len(marcfinditb)
totallength = Len(frmFaultview.RichTextBox1.Text)
start = 0
Do Until start >= totallength
foundpos3 = frmFaultview.RichTextBox1.Find(marcfinditb, start, totallength, Text)
If foundpos3 = -1 Then Exit Do
If foundpos3 <> -1 Then 'asterisk found
foundpos4 = frmFaultview.RichTextBox1.Find(marcfinditb, foundpos3 + 1, totallength, Text)
If foundpos4 = -1 Then Exit Do
If foundpos4 <> -1 Then
frmFaultview.RichTextBox1.SelStart = foundpos3
frmFaultview.RichTextBox1.SelLength = foundpos4 - foundpos3 + 1
frmFaultview.RichTextBox1.SelBold = True
frmFaultview.RichTextBox1.SelColor = RGB(125, 245, 134)
start = foundpos4 + 1 ' start looking here
End If
End If
Loop
frmFaultview.RichTextBox1.SelStart = 0
frmFaultview.RichTextBox1.SelBold = False
frmFaultview.RichTextBox1.SelColor = RGB(0, 0, 0)
marcfindita = "!"
marcfinditb = "*"
lengther = Len(marcfindita)
totallength = Len(frmFaultview.RichTextBox1.Text)
start = 0
Do Until start >= totallength
foundpos1 = frmFaultview.RichTextBox1.Find(marcfindita, start, totallength, Text)
If foundpos1 = -1 Then Exit Do
If foundpos1 <> -1 Then 'exclamation mark found
foundpos2 = frmFaultview.RichTextBox1.Find(marcfindita, foundpos1 + 1, totallength, Text)
If foundpos2 = -1 Then Exit Do
If foundpos2 <> -1 Then
frmFaultview.RichTextBox1.SelStart = foundpos1
frmFaultview.RichTextBox1.SelLength = foundpos2 - foundpos1 + 1
frmFaultview.RichTextBox1.SelBold = True
frmFaultview.RichTextBox1.SelColor = RGB(255, 0, 0)
start = foundpos2 + 1 ' start looking here
End If
End If
Loop
lengther = Len(marcfinditb)
totallength = Len(frmFaultview.RichTextBox1.Text)
start = 0
Do Until start >= totallength
foundpos3 = frmFaultview.RichTextBox1.Find(marcfinditb, start, totallength, Text)
If foundpos3 = -1 Then Exit Do
If foundpos3 <> -1 Then 'asterisk found
foundpos4 = frmFaultview.RichTextBox1.Find(marcfinditb, foundpos3 + 1, totallength, Text)
If foundpos4 = -1 Then Exit Do
If foundpos4 <> -1 Then
frmFaultview.RichTextBox1.SelStart = foundpos3
frmFaultview.RichTextBox1.SelLength = foundpos4 - foundpos3 + 1
frmFaultview.RichTextBox1.SelBold = True
frmFaultview.RichTextBox1.SelColor = RGB(125, 245, 134)
start = foundpos4 + 1 ' start looking here
End If
End If
Loop
frmFaultview.RichTextBox1.SelStart = 0
frmFaultview.RichTextBox1.SelBold = False
frmFaultview.RichTextBox1.SelColor = RGB(0, 0, 0)
#6
Re: Appending Text to a Richtextbox
Posted 30 July 2008 - 05:02 AM
Does that mean you tried my latest suggestion or not?
I did a quick little experiment and my suggestion not only works, but it doesn't erase the previous formatting:
If for some reason you cannot use this method, then I'm out of advice.
I did a quick little experiment and my suggestion not only works, but it doesn't erase the previous formatting:
Private Sub Command1_Click() rtbMain.SelStart = Len(rtbMain.Text) rtbMain.SelText = "apples" End Sub Private Sub Form_Load() rtbMain.SelStart = 2 rtbMain.SelLength = 1 rtbMain.SelColor = vbGreen rtbMain.SelStart = Len(rtbMain.Text) End Sub
If for some reason you cannot use this method, then I'm out of advice.

This post has been edited by Zhalix: 30 July 2008 - 05:04 AM
#7
Re: Appending Text to a Richtextbox
Posted 30 July 2008 - 05:04 AM
I'll try it and get back to you
#8
Re: Appending Text to a Richtextbox
Posted 01 August 2008 - 06:59 AM
That worked beautifully - Thanks heaps for your help
Page 1 of 1