Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 107,664 VB Programmers for FREE! Ask your question and get quick answers from experts. There are 1,056 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Appending Text to a Richtextbox

 
Reply to this topicStart new topic

Appending Text to a Richtextbox

austevo
post 30 Jul, 2008 - 02:46 AM
Post #1


New D.I.C Head

*
Joined: 30 Jul, 2008
Posts: 5

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
User is offlineProfile CardPM

Go to the top of the page


Zhalix
post 30 Jul, 2008 - 03:19 AM
Post #2


D.I.C Head

**
Joined: 7 May, 2008
Posts: 216



Thanked 8 times
My Contributions


That function doesn't exist with VB 6's RTB. If you're looking to append the text, you can do something like this:

CODE
RTB.Text = RTB.Text & String & vbNewLine


User is offlineProfile CardPM

Go to the top of the page

austevo
post 30 Jul, 2008 - 03:23 AM
Post #3


New D.I.C Head

*
Joined: 30 Jul, 2008
Posts: 5

QUOTE(Zhalix @ 30 Jul, 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:

CODE
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.
User is offlineProfile CardPM

Go to the top of the page

Zhalix
post 30 Jul, 2008 - 04:32 AM
Post #4


D.I.C Head

**
Joined: 7 May, 2008
Posts: 216



Thanked 8 times
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

austevo
post 30 Jul, 2008 - 04:58 AM
Post #5


New D.I.C Head

*
Joined: 30 Jul, 2008
Posts: 5

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)
User is offlineProfile CardPM

Go to the top of the page

Zhalix
post 30 Jul, 2008 - 05:02 AM
Post #6


D.I.C Head

**
Joined: 7 May, 2008
Posts: 216



Thanked 8 times
My Contributions


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:

CODE
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. tongue.gif

This post has been edited by Zhalix: 30 Jul, 2008 - 05:04 AM
User is offlineProfile CardPM

Go to the top of the page

austevo
post 30 Jul, 2008 - 05:04 AM
Post #7


New D.I.C Head

*
Joined: 30 Jul, 2008
Posts: 5

I'll try it and get back to you
User is offlineProfile CardPM

Go to the top of the page

austevo
post 1 Aug, 2008 - 06:59 AM
Post #8


New D.I.C Head

*
Joined: 30 Jul, 2008
Posts: 5

That worked beautifully - Thanks heaps for your help
User is offlineProfile CardPM

Go to the top of the page

Zhalix
post 1 Aug, 2008 - 10:03 AM
Post #9


D.I.C Head

**
Joined: 7 May, 2008
Posts: 216



Thanked 8 times
My Contributions


Yay. icon_up.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 10:46PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month