|
-
Mar 17th, 2005, 03:51 PM
#1
Option Strict - Disallowed implicit conversion [Resolved]
I am using Option Explicit and Option Strict in my project and I have come accross an error where an implicit
conversion is taking place.
I have a LinearGradientMode and a String array. The LGM is being set from the srting array lie so. How do I convert
it so it wont error?
VB Code:
'drawParts() is the string array.
If Not IsNothing(drawParts(0)) Then _GradientPanel.DrawMode = [color=red]drawParts(0)[/color]
Last edited by RobDog888; Mar 17th, 2005 at 05:40 PM.
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 
-
Mar 17th, 2005, 04:02 PM
#2
Re: Option Strict - Disallowed implicit conversion
drawParts(0) contains the actual constant name? like "horizontal" or whatever?
-
Mar 17th, 2005, 04:02 PM
#3
Re: Option Strict - Disallowed implicit conversion
VB Code:
GradientPanel.DrawMode = CType(drawParts(0), System.Drawing.Drawing2D.LinearGradientMode)
-
Mar 17th, 2005, 04:04 PM
#4
Re: Option Strict - Disallowed implicit conversion
 Originally Posted by ntg
VB Code:
GradientPanel.DrawMode = CType(drawParts(0), System.Drawing.Drawing2D.LinearGradientMode)
will that work if the string contains the contant name and not the actual value of the enum?
-
Mar 17th, 2005, 04:09 PM
#5
Re: Option Strict - Disallowed implicit conversion
Nope. Neither would GradientPanel.DrawMode = drawParts(0). You would need the value of the constant in the string, otherwise you'd need to fiddle with .ToString().
-
Mar 17th, 2005, 04:11 PM
#6
Re: Option Strict - Disallowed implicit conversion
That should work, but I cant test it until I get all the conversion errors fixed.
This is the other one:
VB Code:
If Not IsNothing(drawParts(1)) Then _GradientPanel.PanelColor1 = CType(drawParts(1), System.Drawing.Color)
Says string can not be converted to a color.
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 
-
Mar 17th, 2005, 04:14 PM
#7
Re: Option Strict - Disallowed implicit conversion
i was thinking you could do something like this.. not sure if its overkill.. im not even sure if it works since i dont have anything to test it against....
VB Code:
For Each EnumName As String In [Enum].GetNames(GetType(LinearGradientMode))
If EnumName = drawParts(0) Then
_GradientPanel.DrawMode = [Enum].GetValues(GetType(LinearGradientMode)).GetValue(0)
End If
Next
-
Mar 17th, 2005, 04:18 PM
#8
Re: Option Strict - Disallowed implicit conversion
That shouldn't have something to do with Option Strict, right ? That's because System.Drawing.Color isn't an enumeration but a class with shared members. You shouldn't be able to do this using Option Explicit either.
I would think that should read:
VB Code:
If EnumName.ToString() = drawParts(0) Then
right ?
-
Mar 17th, 2005, 04:19 PM
#9
Re: Option Strict - Disallowed implicit conversion
well in my example enumname already is a string...
[Enum].GetNames(GetType(LinearGradientMode))
returns a string array
-
Mar 17th, 2005, 04:21 PM
#10
Re: Option Strict - Disallowed implicit conversion
-
Mar 17th, 2005, 04:57 PM
#11
Re: Option Strict - Disallowed implicit conversion
So then how do I fix the one for the color?
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 
-
Mar 17th, 2005, 05:07 PM
#12
Re: Option Strict - Disallowed implicit conversion
VB Code:
color.fromname(drawParts(1))
i think should do it
-
Mar 17th, 2005, 05:13 PM
#13
Re: Option Strict - Disallowed implicit conversion
Havent ran it yet but no error lines 
Will this cover if the color is an RGB?
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 
-
Mar 17th, 2005, 05:20 PM
#14
Re: Option Strict - Disallowed implicit conversion
 Originally Posted by RobDog888
Havent ran it yet but no error lines 
Will this cover if the color is an RGB?
ummmmmmm NO, it takes a color name as a param..
there is color.FromArgb() which you can pass an integer color value, or pass a red, green, and blue value to (its overloaded).. so i guess it depends on how your string looks...
like if your string is "255,255,255" you might need to write a little function that parses and returns an array of integers to pass to the color.FromArgb() function
-
Mar 17th, 2005, 05:31 PM
#15
Re: Option Strict - Disallowed implicit conversion
Damn, the thing is that its a property. So the user could enter a RGB or select a known color.
Got this error when I built the control:
Code generation for property 'Controls' failed. Error was: ''GraphicsModeConverter' is unable to convert 'MyUC.GradientPanelControl.GradientPanel' to 'System.ComponentModel.Design.Serialization.InstanceDescriptor'.'
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 
-
Mar 17th, 2005, 05:39 PM
#16
Re: Option Strict - Disallowed implicit conversion
Ok, I rebuilt both the control's project and the test project and the error went away. I tested under an known
named color and an RGB and it appears to work without errors but my properties are not expandable
properties.
Thanks for the help ntg and kleinma 
Please see Expandable Properties thread for the other part of this issue.
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 
-
Mar 17th, 2005, 05:53 PM
#17
Re: Option Strict - Disallowed implicit conversion [Resolved]
You can use the Parse method of the Enum type to convert a constant name into it's appropriate value, i.e.
VB Code:
_GradientPanel.DrawMode = [Enum].Parse(GetType(LinearGradientMode), drawParts(0))
If Not IsNumeric(drawParts(1)) Then
_GradientPanel.PanelColor1 = [Enum].Parse(GetType(KnownColor), drawParts(1))
Else
_GradientPanel.PanelColor1 = Color.FromArgb(Convert.ToInt32(drawParts(1)))
End If
-
Mar 17th, 2005, 06:02 PM
#18
Re: Option Strict - Disallowed implicit conversion [Resolved]
Cool! 
You always make things look so easy!
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
|