Results 1 to 13 of 13

Thread: Helo with a simple 'color code' thingy in vb6.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    22

    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
    Last edited by SpioR; Feb 6th, 2011 at 10:09 AM. Reason: I *****ed up the title :/

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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:
    1. Private Sub Form_Load()
    2.     DHTMLEdit1.DocumentHTML = "<html><body><font color=""red"">Test</font><font color=""green"">Test</font><font color=""yellow"">Test</font></body></html>"
    3. End Sub


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    22

    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
    If it was just testtest that would be easy

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Helo with a simple 'color code' thingy in vb6.

    You want to know how to color it or to hide it ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    22

    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:

  6. #6
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    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.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  7. #7
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Helo with a simple 'color code' thingy in vb6.

    I did a quick example:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim i As Long
    5.     Dim j As Long
    6.     Dim k As Long
    7.    
    8.     i = 1
    9.     k = 0
    10.     Do While i < Len(RichTextBox1.Text) And k <> Len(RichTextBox1.Text)
    11.         j = InStr(i, RichTextBox1.Text, "^", vbTextCompare)             '~~~ Starting marker's position
    12.         k = InStr(j + 1, RichTextBox1.Text, "^", vbTextCompare) - 1     '~~~ End marker's position
    13.        
    14.         If k = -1 Then k = Len(RichTextBox1.Text)   '~~~ If an end marker is not found, the text upto the end will be selected
    15.        
    16.         '~~~ Selecting the text
    17.         RichTextBox1.SelStart = j
    18.         RichTextBox1.SelLength = k - j
    19.        
    20.         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
    21.        
    22.         RichTextBox1.SetFocus   '~~~ To see the selection
    23.        
    24.         i = k
    25.        
    26.     Loop
    27.    
    28.    
    29. End Sub
    See if it could get you started.

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    22

    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.

  9. #9
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Helo with a simple 'color code' thingy in vb6.

    Quote Originally Posted by SpioR View Post
    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.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    22

    Re: Helo with a simple 'color code' thingy in vb6.

    hmm kk then...

  11. #11
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    22

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

  13. #13
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Helo with a simple 'color code' thingy in vb6.

    Quote Originally Posted by Merri View Post
    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


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width