Results 1 to 10 of 10

Thread: change color

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    change color

    i need to search a richtextbox for any text between << text >>

    then change its color to blue including the word befor the brackets

    example:
    text befor searching
    In all our MBA and MSc programmes, you can <<choose from a range>> of elective modules to personalise the content of your degree. Alternatively, you can follow one of <<our Specialisation>> Tracks to acquire a more focused set of skills and knowledge. This means that you can choose modules that are relevant to your <<needs today as well>> as those that will formalise your

    text after searching
    In all our MBA and MSc programmes, you can <<choose from a range>> of elective modules to personalise the content of your degree. Alternatively, you can follow one of <<our Specialisation>> Tracks to acquire a more focused set of skills and knowledge. This means that you can choose modules that are relevant to your <<needs today as well>> as those that will formalise your

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: change color

    You may want to read about moeur's RTB in CodeBank - http://vbforums.com/showthread.php?t=355994
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: change color

    is there any simplist way to do it without using modules
    because i'm new in VB and i need a simple code that i can understand

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: change color

    Try
    VB Code:
    1. Dim i As Long
    2.     With RichTextBox1
    3.         For i = 1 To Len(.Text)
    4.             If Mid(.Text, i, 1) = "<<" Then
    5.                 .SelStart = i
    6.                 .SelLength = InStr(i, .Text, ">>") - i - 1
    7.                 .SelColor = vbBlue
    8.                 .SelBold = True
    9.             End If
    10.         Next
    11.     End With

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: change color

    Hack
    it didn't work
    whats the problem?

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: change color

    VB Code:
    1. [B]Dim y As Integer[/B]
    2.     Dim i As Long
    3.     With RichTextBox1
    4.         For i = 1 To Len(.Text)
    5.             If Mid(.Text, i, 2) = "<<" And i > 2 Then
    6.               [B]y = InStrRev(.Text, " ", i - 2)[/B]
    7.                 .SelStart = [B]y[/B]   'i - 2 -
    8.                 .SelLength = InStr(i, .Text, ">>")  -[B] y[/B] + 2
    9.                 .SelColor = vbBlue
    10.                 .SelBold = True
    11.             End If
    12.         Next
    13.     End With
    Is what it should be like.
    Last edited by Ember; Jan 3rd, 2007 at 05:34 PM.

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: change color

    Quote Originally Posted by om-yousif
    is there any simplist way to do it without using modules
    because i'm new in VB and i need a simple code that i can understand
    Omg...

    Module is the same as a Form - actually, better. If you declare a variable with a simple 'Dim' and you put it in a Module that variable is accessible from any module in your app (Form, Module, Class...). It's quite usefull to 'group' methods/functions also... And that's it - nothing more, nothing complicated and hard to understand.

    Cheers

  8. #8
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: change color

    @Ember: don't want to be critical, but... your code works in general (if you have "...blah blah <<blah>>..."). But there's a problem if you have only "<<blah" withouth ">>". You'll need to search for ">>" also before aplying the colour

  9. #9
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: change color

    Quote Originally Posted by gavio
    @Ember:<<blah" withouth ">>". You'll need to search for ">>" also before aplying the colour
    I thought of it an d edited the code. Things like that can happen. Sorry!

  10. #10

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