Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Request / Listing] [VB6]Richtextbox questions  (Read 4005 times)

0 Members and 1 Guest are viewing this topic.
[Request / Listing] [VB6]Richtextbox questions
« on: May 11, 2006, 09:22:12 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 562
How would I make it so that whenever "/" is found at the beginning of a line it makes that whole line green. Please help me, I want to learn this for future reference.
BTW: I tried google.
« Last Edit: February 24, 2012, 07:01:59 pm by Niek »
Logged
Re: [VB6]Richtextbox questions
« Reply #1 on: May 11, 2006, 10:03:40 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
I'm working on the response, and will have a nice interpretter for you here. Check back in 15 minutes! =)
Logged
Re: [VB6]Richtextbox questions
« Reply #2 on: May 11, 2006, 10:30:15 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
The first bit of advice I can offer you is that you should try to avoid VB6's built-in objects: most of them are well programmed, but they're very abstracted, and so you'll never have complete control over them without hecking into their message queues... at which point, you would have done well to just roll your own controls in the first place. =)

But, if you simply must use the built-in objects, let me help you.

First, don't use the character '/' as a tag. Instead, I recommend that you use html-esque tags; in this case, our interpreter will make all the text between the tags <green> and </green> be green.

So, here's the function you're going to want to use: it reads in a line of text, and outputs rtftext which can be set to a richtextbox's textrtf property. =)

Code: [Select]
Private Function sGetRTFText(ByVal nText As String) As String
    Dim iLines() As String, i As Long
    Dim iWords() As String, j As Long
    Dim iThisLine As String, iFollowingTag As Long

    nText = Replace(nText, vbCrLf, "<br>", , , vbTextCompare)
    nText = Replace(nText, "<", " <", , , vbTextCompare)
    nText = Replace(nText, ">", "> ", , , vbTextCompare)
    iLines = Split(nText, "<br>", , vbTextCompare)

    For i = LBound(iLines) To UBound(iLines)
        If iLines(i) <> vbNullString Then
            iWords = Split(iLines(i), " ", , vbTextCompare)
            For j = LBound(iWords) To UBound(iWords)
                If iWords(j) <> vbNullString Then
                Select Case LCase(iWords(j))
                Case "<green>"
                    iThisLine = iThisLine & "\cf1 "
                Case "</green>"
                    iThisLine = iThisLine & "\cf0 "
                    iFollowingTag = 1
                Case Else
                    iThisLine = iThisLine & iWords(j) & " "
                End Select
                End If
            Next j
            sGetRTFText = sGetRTFText & iThisLine & "\par "
            iThisLine = vbNullString
        End If
    Next i
   
    'add the header, the font table, and the color table.
    sGetRTFText = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}" & _
    "{\colortbl ;\red0\green128\blue0;}" & sGetRTFText & "}"

End Function

A good test of this code's functionality would be to try this:
Code: [Select]
rtfOutput.TextRTF = sGetRTFText("Some test text:<br>Hello World!<br>This word is <green>green</green>!")
« Last Edit: May 11, 2006, 10:33:38 pm by FarFromHomeFish »
Logged

Dayjo

shut the fuck up donny.
Re: [VB6]Richtextbox questions
« Reply #3 on: May 11, 2006, 10:42:07 pm »
  • hungry..
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3602
I think he's wanting to use "/" so that he can write a comment line.

so like;
//This is a comment

would be green.
Logged
  • My Blog
Re: [VB6]Richtextbox questions
« Reply #4 on: May 11, 2006, 11:05:28 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
Oh! I hadn't considered that. =P

That would make it even easier, then. Simply check if the string "//" appears in a line. If it does, then insert the color identifier "\cf1" before it and the identifier "\cf0" at the end of the line, before "\par".
Logged
Re: [VB6]Richtextbox questions
« Reply #5 on: May 12, 2006, 01:05:27 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 562
Oh! I hadn't considered that. =P

That would make it even easier, then. Simply check if the string "//" appears in a line. If it does, then insert the color identifier "\cf1" before it and the identifier "\cf0" at the end of the line, before "\par".
Can you edit the previous code to encorperate this? XD
Logged
Re: [VB6]Richtextbox questions
« Reply #6 on: May 12, 2006, 01:07:49 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 562
Oh! I hadn't considered that. =P

That would make it even easier, then. Simply check if the string "//" appears in a line. If it does, then insert the color identifier "\cf1" before it and the identifier "\cf0" at the end of the line, before "\par".
Can you edit the previous code to encorperate this? XD

EDIT: Basicly I want it like and HTML Editor such as Dreamweaver. I want it so whenever you see "//" on the line it makes the whole line green. I want it viewable in the program not when I save the RTF.
Logged
Re: [VB6]Richtextbox questions
« Reply #7 on: May 12, 2006, 03:25:43 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
Well, yes. I could. But you're not going to learn anything by making me do all your work for you. =)

I'll start you out: to check if one string occurs in another string, you can use VB6's built-in InStr command. Like so:

iPosition = InStr(1, iLine, "//", vbTextCompare)
If iPosition > 0 then
...
End If

To make a color-coded code editor, you're going to have to do what every other code editor out there does: you need to keep the code seperate from the display text. When you update the code that matters, you then update the display rtf.

Again: keep the display rtftext seperate from the text that you are editing.
Logged
Re: [VB6]Richtextbox questions
« Reply #8 on: May 12, 2006, 04:07:20 am »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
If InStr(1, t, "//", vbTextCompare) Then

1 : Starting Point
2 : String We Search
3 : Character(s) we Search
4 : Comparison Type.

Depending on how text is drawn, you could make the colour type green. It'd be easier to do /* and */. That's my brain yappign on...
Logged
the a o d c
Re: [VB6]Richtextbox questions
« Reply #9 on: May 12, 2006, 12:40:18 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 562
If InStr(1, t, "//", vbTextCompare) Then

1 : Starting Point
2 : String We Search
3 : Character(s) we Search
4 : Comparison Type.

Depending on how text is drawn, you could make the colour type green. It'd be easier to do /* and */. That's my brain yappign on...
So would this be it?:
Code: [Select]
Private Sub RichTextBox1_Change()
If InStr(1, t, "*/", vbTextCompare) Then
RichTextBox1.SelColor = QBColor(2)
End If
End Sub
Logged
Re: [VB6]Richtextbox questions
« Reply #10 on: May 13, 2006, 11:53:38 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 562
bumpity bump bump
Logged
Re: [VB6]Richtextbox questions
« Reply #11 on: May 13, 2006, 01:06:27 pm »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
t is the string you are searching, change it to the name of the text. (eg Text1.Text, or whichever input object you use.)

I am not sure how lines would work... Hmm. I really need to study up VB more :/
Logged
the a o d c
Re: [VB6]Richtextbox questions
« Reply #12 on: May 13, 2006, 01:50:55 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 562
t is the string you are searching, change it to the name of the text. (eg Text1.Text, or whichever input object you use.)

I am not sure how lines would work... Hmm. I really need to study up VB more :/
ohhh, lol, ok!

Then how do you make the whole line a color? XD

EDIT:
Code: [Select]
Private Sub Richtextbox1_KeyPress(KeyAscii As Integer)
If InStr(2, RichTextBox1.TextRTF, "comment<", vbTextCompare) Then
RichTextBox1.SelColor = QBColor(2)
End If
If InStr(2, RichTextBox1.TextRTF, ">", vbTextCompare) Then
RichTextBox1.SelColor = QBColor(0)
End If
End Sub
I found an error in that coding. If you type "comment<testing>" and then you press enter and try to type it again it only turns out black instead of green. Is there a way to loop this?
« Last Edit: May 13, 2006, 02:34:13 pm by Water Rider »
Logged
Re: [VB6]Richtextbox questions
« Reply #13 on: May 13, 2006, 04:41:13 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 150
You're using .selColor, silly! You need to use .textrtf (or is it .rtftext?); selColor only works for the selected text.
Logged
Re: [VB6]Richtextbox questions
« Reply #14 on: May 13, 2006, 08:54:34 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 562
You're using .selColor, silly! You need to use .textrtf (or is it .rtftext?); selColor only works for the selected text.
OH!

EDIT:
.textrtf doesn't work it makes my text turn into
Quote
32768
« Last Edit: May 13, 2006, 08:56:21 pm by Water Rider »
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.051 seconds with 67 queries.