convert from one type to another
-
Hi There, Would like some help on this.... How do I convert from a string to system.drawing.color ie.. "color.blue" to color.blue might seems simple to you, but at the momnet it eldues me.:)
-
Hi There, Would like some help on this.... How do I convert from a string to system.drawing.color ie.. "color.blue" to color.blue might seems simple to you, but at the momnet it eldues me.:)
You can do it two ways: 1.
Dim ColorVar as System.Drawing.Color = Color.Blue
MsgBox(ColorVar.ToString)Which will display
Color[Blue]
2.Dim ColorVar as System.Drawing.Color = Color.Blue
MsgBox(ColorVar.Name)Which will display
Blue
Hope this helps!
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
You can do it two ways: 1.
Dim ColorVar as System.Drawing.Color = Color.Blue
MsgBox(ColorVar.ToString)Which will display
Color[Blue]
2.Dim ColorVar as System.Drawing.Color = Color.Blue
MsgBox(ColorVar.Name)Which will display
Blue
Hope this helps!
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
This is what i am trying to do... 'Changes the Colour of the Form's BackGround Colour. Dim RandomValue As Integer Dim Upper, Lower As Integer Dim NewColour As Color Upper = ListBox1.Items.Count Lower = 0 RandomValue = CInt(Int(Upper - Lower + 0) * Rnd() + Lower) NewColour = ListBox1.Items(RandomValue) Me.BackColor = NewColour the listbox contains the following :- color.red color.blue color.black color.yellow
-
This is what i am trying to do... 'Changes the Colour of the Form's BackGround Colour. Dim RandomValue As Integer Dim Upper, Lower As Integer Dim NewColour As Color Upper = ListBox1.Items.Count Lower = 0 RandomValue = CInt(Int(Upper - Lower + 0) * Rnd() + Lower) NewColour = ListBox1.Items(RandomValue) Me.BackColor = NewColour the listbox contains the following :- color.red color.blue color.black color.yellow
I think you might be better off using an
If
statement.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
I think you might be better off using an
If
statement.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
in what way....:confused: this is the line where the problem is NewColour = ListBox1.Items(RandomValue) that is why i need to find out how to convert from a string "color.blue" to the system.drawing.color type color.blue
-
in what way....:confused: this is the line where the problem is NewColour = ListBox1.Items(RandomValue) that is why i need to find out how to convert from a string "color.blue" to the system.drawing.color type color.blue
WestSideRailways wrote:
NewColour = ListBox1.Items(RandomValue)
What is the type of the variable NewColour? The ListBox item stores strings, so you should use string comparisons in your if statements. If NewColour="Color.Blue" System.Drawing.Color = Color.Blue and similarly for all other colors HTH
-
WestSideRailways wrote:
NewColour = ListBox1.Items(RandomValue)
What is the type of the variable NewColour? The ListBox item stores strings, so you should use string comparisons in your if statements. If NewColour="Color.Blue" System.Drawing.Color = Color.Blue and similarly for all other colors HTH
ChandraRam wrote:
What is the type of the variable NewColour?
trying not to be too blunt, but if you look at the 2nd answer, you will find that i am NOT using "IF" statements. And the variable "newcolour" is of type color.
-
ChandraRam wrote:
What is the type of the variable NewColour?
trying not to be too blunt, but if you look at the 2nd answer, you will find that i am NOT using "IF" statements. And the variable "newcolour" is of type color.
WestSideRailways wrote:
trying not to be too blunt
Same here... If you look at my answer, you will see I have told you that a Listbox stores "strings"... and not variables of any other type. If you need to be able to set color based on a selection from a list box, change the type of NewColour to string and use the IF statements. HTH
-
WestSideRailways wrote:
trying not to be too blunt
Same here... If you look at my answer, you will see I have told you that a Listbox stores "strings"... and not variables of any other type. If you need to be able to set color based on a selection from a list box, change the type of NewColour to string and use the IF statements. HTH
ok then, i took your answer another way.... Still does not answer my question thou... I take it that it cannot be done.!!