8 Replies - 14108 Views - Last Post: 01 August 2008 - 10:03 AM Rate Topic: -----

#1 austevo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-July 08

Appending Text to a Richtextbox

Post icon  Posted 30 July 2008 - 02:46 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Appending Text to a Richtextbox

#2 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

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

Was This Post Helpful? 0
  • +
  • -

#3 austevo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-July 08

Re: Appending Text to a Richtextbox

Posted 30 July 2008 - 03:23 AM

View PostZhalix, 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.
Was This Post Helpful? 0
  • +
  • -

#4 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

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.
Was This Post Helpful? 0
  • +
  • -

#5 austevo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-July 08

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)
Was This Post Helpful? 0
  • +
  • -

#6 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

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:

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. :P

This post has been edited by Zhalix: 30 July 2008 - 05:04 AM

Was This Post Helpful? 1
  • +
  • -

#7 austevo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-July 08

Re: Appending Text to a Richtextbox

Posted 30 July 2008 - 05:04 AM

I'll try it and get back to you
Was This Post Helpful? 0
  • +
  • -

#8 austevo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-July 08

Re: Appending Text to a Richtextbox

Posted 01 August 2008 - 06:59 AM

That worked beautifully - Thanks heaps for your help
Was This Post Helpful? 0
  • +
  • -

#9 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: Appending Text to a Richtextbox

Posted 01 August 2008 - 10:03 AM

Yay. :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1