Results 1 to 15 of 15

Thread: Rich Text Box Highlighting

  1. #1

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943

    Rich Text Box Highlighting

    Okay, maybe some of you read my thread in chit-chat, maybe some of you didn't, but I've decided to start the program now and realized I know a lot less about rich text boxes than I thought I did. Is there a way to change the background color of certain numbers, or even just make them bold?? I plan on searching the rich text box for certain numbers or patterns of numbers but I want to have a way to highlight them to see if they form a pattern (to hopefully work on a theory of mine). Any help??
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    To highlight, you can use the SelStart and SelLength properties, unless I misunderstood you.

    And bolding is easy (SelBold property), but changing the background only on certain text is tough. You can search the forum for the API's involved.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    Can I select mulutiple non-sequential things though?? Im taking the first 10,000 digits of pi and searching it for certain numbers which will not be next to eachother. Maybe I should find a different way to do this??
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  4. #4
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    Joe, don't help him.

    Don't want him to win the nobel's price..

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Skitchen8
    Can I select mulutiple non-sequential things though?? Im taking the first 10,000 digits of pi and searching it for certain numbers which will not be next to eachother. Maybe I should find a different way to do this??
    Not all at once, no. But you could loop through and bold each part as you hit them.
    Last edited by crptcblade; Feb 28th, 2004 at 02:59 PM.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Michael_Kamen
    Joe, don't help him.

    Don't want him to win the nobel's price..
    If there is cash involved, I'll do anything.


    That's right, you heard me...
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    Originally posted by crptcblade
    If there is cash involved, I'll do anything.


    That's right, you heard me...
    Well, I know a few people with too much cash on their hands and lots of sickminded ideas..

  8. #8

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    Originally posted by crptcblade
    Not all at once, no. But you could loop through and bold each part as you hit them.
    so maybe do a for next loop like

    VB Code:
    1. Dim i As Integer
    2. For i = 1 To Len(rtf1.Text)
    3.  
    4.  
    5. Next i


    Wow... its been a long time since I've been here, and about the same amount of time since I've touched VB. I was at first thinking of using left$ or right$ to see if the character at position i equals whatever is in texthighl.text, but then I realized that those took all the characters left or right of position i. Then I thought i could use instr to find out if the character between i and i+len(texthighl.text) was what was in texthighl.text, but I can't seem to do that either. I am absolutely lost at the moment.

    I tried to do "rtf1.Text = Replace(rtf1.Text, texthighl.text, "{\b" & texthighl.text & "\b0}")" thinking that I could just replace the characters with their bold equivalent in RTF code, but that doesn't work either, it just types out {\b.... in the box.


    Wow, I figured this would be easy too...
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  9. #9
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    Do you mean something like this?

    VB Code:
    1. Dim i As Integer
    2. For i = 1 To Len(RTF1.Text)
    3. If Mid(RTF1.Text,i, i +1) = CharacterIWantBold Then
    4. 'highlight character here
    5. End
    6. Next

  10. #10
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    I'm still thinking about the hightlight section..


    And I'm not sure if this is the most optimized way to do it.
    I usually don't like If Statements in a Loop.
    Especially not when that loop will run for about 10,000 times..

  11. #11

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    ding ding ding, mid is the function (errr... sub I guess) that I was looking for, thank you


    I still however cannot get it to work right with the following code (texthighl.text changed back to original text1.text because that is quicker to type).

    VB Code:
    1. Dim i As Integer
    2. For i = 1 To Len(rtf1.Text)
    3. If Mid(rtf1.Text, i, i + Len(Text1.Text)) = Text1.Text Then
    4. rtf1.SelStart = i
    5. rtf1.SelLength = 1
    6. rtf1.SelBold
    7. End If
    8. Next i

    It hangs up for a second while it is looping but it never ends up making anything bold, any help??
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  12. #12

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    Originally posted by Michael_Kamen
    I'm still thinking about the hightlight section..


    And I'm not sure if this is the most optimized way to do it.
    I usually don't like If Statements in a Loop.
    Especially not when that loop will run for about 10,000 times..
    I know that its not very optimized, but since this program will be distributed only to me and anyone else that asks Im not chasing after optimization of code. If it works it works even if it takes 10 minutes to go through the loop.
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  13. #13
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    Actually, this code does the trick:

    VB Code:
    1. Dim i As Integer
    2. For i = 1 To Len(RTF1.Text)
    3. If Mid(RTF1.Text, i, Len(Text1.Text)) = Text1.Text Then
    4. RTF1.SelStart = i - 1
    5. RTF1.SelLength = 1
    6. RTF1.SelBold = True
    7. End If
    8. Next i

  14. #14

    Thread Starter
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    You are a genius, if I ever win a nobel prize both of you are getting fair shares of it

    Although preliminary results are not turning up the patterns I was hoping for... this still needs a lot of work on my part to get it to different line lengths and looking for different things to be significant, but thank you so very much
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  15. #15
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    Thanks and no problem..
    And good luck with your 'Pi' project..

    If I'm even gonna win a nobel prize, it won't be for computer science..

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