Helo with a simple 'color code' thingy in vb6.
Ok so. I tried to do this with a rich text box.
You enter ^1Test^2Test^3Test and it converts it to TestTestTest.
But I'm really having trouble removing the '^1' and '^2' stuff without losing the colors.
I tried replace and I was wondering if there is any other way I could do it.
Anyway thanks :)
EDIT: Help*. Stupid keyboard :D
Re: Helo with a simple 'color code' thingy in vb6.
So, you don't want to display the markers that you used to color the text ?
I think, it is better to use a DHTMLedit control or a WebBroser control instead of RichTextBox control, so that you could use the HTML styling to your text.
An example using DHTMLedit control (Project menu --> Components --> DHTML Edit Control for IE5):
vb Code:
Private Sub Form_Load()
DHTMLEdit1.DocumentHTML = "<html><body><font color=""red"">Test</font><font color=""green"">Test</font><font color=""yellow"">Test</font></body></html>"
End Sub
:wave:
Re: Helo with a simple 'color code' thingy in vb6.
I didn't mean just these TestTestTest stuff.
I ment like I write something with the ^1, ^2 stuff and it gets colored :o
If it was just testtest that would be easy :D
Re: Helo with a simple 'color code' thingy in vb6.
You want to know how to color it or to hide it ? :confused:
Re: Helo with a simple 'color code' thingy in vb6.
<.<
Color the text and remove the ^1, ^2 stuff.
Sounds simple, but it's not D:
Re: Helo with a simple 'color code' thingy in vb6.
So, you're using ^1, ^2, etc. as your own personal markup symbols? That is, the user types ^1Text^2Is^3Here and somehow triggers your routine which converts everything following the ^1 until the ^2 to be the first color, etc. Is this correct? I tend to agree that switching to HTML could be simpler. The underlying RTF syntax is like LaTeX, but evil instead of good.
If you want to use RTF, post your current code. If you have color coding working, it's strange that you can't just Replace$(MyRTF.TextRTF, "^1", "") and get rid of the markup.
Re: Helo with a simple 'color code' thingy in vb6.
I did a quick example:
vb Code:
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim j As Long
Dim k As Long
i = 1
k = 0
Do While i < Len(RichTextBox1.Text) And k <> Len(RichTextBox1.Text)
j = InStr(i, RichTextBox1.Text, "^", vbTextCompare) '~~~ Starting marker's position
k = InStr(j + 1, RichTextBox1.Text, "^", vbTextCompare) - 1 '~~~ End marker's position
If k = -1 Then k = Len(RichTextBox1.Text) '~~~ If an end marker is not found, the text upto the end will be selected
'~~~ Selecting the text
RichTextBox1.SelStart = j
RichTextBox1.SelLength = k - j
RichTextBox1.SelColor = vbRed '~~~ Coloring it. As this is an illustration on how to color the text, you have to do the coding for selecting the color based on the marker value (^1=red, ^2=green, etc..) yourself
RichTextBox1.SetFocus '~~~ To see the selection
i = k
Loop
End Sub
See if it could get you started. :wave:
Re: Helo with a simple 'color code' thingy in vb6.
Hmm. Yeah works...somehow...but it didn't remove the ^1 :/
And @ jemidiah um...what's the difference between Replace and Replace$ o_o
I always use replace lul.
Re: Helo with a simple 'color code' thingy in vb6.
Quote:
Originally Posted by
SpioR
Hmm. Yeah works...somehow...but it didn't remove the ^1 :/
And @ jemidiah um...what's the difference between Replace and Replace$ o_o
I always use replace lul.
Yeah.. It has to be modified to meet your needs. That code was just an example to get you started.
I think, Replace() will return a Variant whereas Replace$() will return a String.
:wave:
Re: Helo with a simple 'color code' thingy in vb6.
Re: Helo with a simple 'color code' thingy in vb6.
There is an alternative method into this: instead of using SelColor etc. you can instead manipulate TextRTF & SelTextRTF. RTF is a syntax of it's own for marking up text color. However, going this route is on the more advanced side because you have to make sure your output is correct.
akhileshbc: Replace is an exception in VB6's functions, it always takes and returns a String, there is no Variant version of it.
Re: Helo with a simple 'color code' thingy in vb6.
o_o um sorry there, but I have no idea how to use that :/
Never actually heard of it before...
Re: Helo with a simple 'color code' thingy in vb6.
Quote:
Originally Posted by
Merri
akhileshbc: Replace is an exception in VB6's functions, it always takes and returns a String, there is no Variant version of it.
Ah! Thanks for the info :thumb:
:wave: