Results 1 to 9 of 9

Thread: Change text1 color

  1. #1

    Thread Starter
    Addicted Member Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Change text1 color

    Im trying to change text1.text color with a combo box but instead i get a error every time. This is the code i used
    VB Code:
    1. Private Sub text1_change()
    2. Text1.Font = (Combo1.Text)
    3. Text1.FontSize = (Combo3.Text)
    4. Text1.ForeColor = (Combo2.Text)
    5. End Sub

    But the other 2 work fine the forecolor gets a error when i choose the color.
    Are we alive or just breathing?

  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 text1 color

    .Forecolor takes either a normal RGB color value or a System default color.
    What is the value you are trying to set it to?
    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 Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Re: Change text1 color

    I was adding &H00000000& ( black ) and &H00FFFFFF& ( white ) and few others
    Are we alive or just breathing?

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

    Re: Change text1 color

    How about adding a explicit conversion instead of letting the ampersand
    char and h do it, since it is in the text property of the combo?

    VB Code:
    1. Text1.ForeColor = CLng(Combo2.Text)
    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

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Change text1 color

    You'll need to convert HEX value to long:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Text1.ForeColor = HexToLong(Trim(Combo1.Text))
    5. End Sub
    6.  
    7. Function HexToLong(ByVal sValue As String) As Long
    8. '===================================================
    9.  
    10.     If UCase(Left(sValue, 2)) <> "&H" Then sValue = "&H" & sValue
    11.     If Right(sValue, 1) <> "&" Then sValue = sValue & "&"
    12.     HexToLong = Val(sValue)
    13.  
    14. End Function

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Change text1 color

    Sorry, Rob - didn't mean to cross post.

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

    Re: Change text1 color

    No prob. Its all about solving the problem at hand.
    I appreciate the help too, keep it coming.
    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

  8. #8

    Thread Starter
    Addicted Member Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Re: Change text1 color

    Quote Originally Posted by RobDog888
    How about adding a explicit conversion instead of letting the ampersand
    char and h do it, since it is in the text property of the combo?

    VB Code:
    1. Text1.ForeColor = CLng(Combo2.Text)
    Im sorry but i do not understand what adding a Explicit conversion is.


    Option Explicit

    Private Sub Command1_Click()
    Text1.ForeColor = HexToLong(Trim(Combo1.Text))
    End Sub

    Function HexToLong(ByVal sValue As String) As Long
    '===================================================

    If UCase(Left(sValue, 2)) <> "&H" Then sValue = "&H" & sValue
    If Right(sValue, 1) <> "&" Then sValue = sValue & "&"
    HexToLong = Val(sValue)

    End Function
    I do not have a command button on my form and was never planning on using one
    Are we alive or just breathing?

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

    Re: Change text1 color

    Explicit is just a term for stating that the conversion needs to be told how to
    convert vs. implicit which just implies a conversion. Implicit conversions could
    be converted to a unexpected type since the conversion is left to the
    system to decide.

    I think that should explain it?

    The command button is just for presenting the possible solution's usage and is in no
    way a requirement. since we dcan not see all your code we can only show
    how it may be used. It is up to you to take the contents and integrate them
    into yur app, unless you want to post all your procedures code?

    HTH
    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

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