|
-
Dec 26th, 2004, 12:59 PM
#1
Thread Starter
Addicted Member
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:
Private Sub text1_change()
Text1.Font = (Combo1.Text)
Text1.FontSize = (Combo3.Text)
Text1.ForeColor = (Combo2.Text)
End Sub
But the other 2 work fine the forecolor gets a error when i choose the color.
Are we alive or just breathing?
-
Dec 26th, 2004, 01:05 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 26th, 2004, 01:08 PM
#3
Thread Starter
Addicted Member
Re: Change text1 color
I was adding &H00000000& ( black ) and &H00FFFFFF& ( white ) and few others
Are we alive or just breathing?
-
Dec 26th, 2004, 01:17 PM
#4
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:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 26th, 2004, 01:19 PM
#5
Re: Change text1 color
You'll need to convert HEX value to long:
VB Code:
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
-
Dec 26th, 2004, 01:20 PM
#6
Re: Change text1 color
Sorry, Rob - didn't mean to cross post.
-
Dec 26th, 2004, 01:25 PM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 26th, 2004, 01:30 PM
#8
Thread Starter
Addicted Member
Re: Change text1 color
 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:
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?
-
Dec 26th, 2004, 01:38 PM
#9
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|