DR00ME Posted February 23, 2004 Posted February 23, 2004 lstRGB.Items.Add(CStr(pixelColor.R) + " " + CStr(pixelColor.G) + " " + CStr(pixelColor.B)) As you can see I have added 3 separate values in the listbox. Dim MyString As String MyString = lstRGB.SelectedItem lets say MyString is like "60 255 132" how do I split it in three parts ? one of them would be 60 second 255 and third 132... can you do it with split or substring ? it is 4am I can't think HELP! :) Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
*Experts* Bucky Posted February 23, 2004 *Experts* Posted February 23, 2004 Yes, use the Split method. Then convert each color into an integer and create a Color structure. Dim MyColors() As String MyColors = MyString.Split(" "c) ' Split MyString by space characters Dim red, green, blue As Integer red = Convert.ToInt32(MyColors(0)) green = Convert.ToInt32(MyColors(1)) blue = Convert.ToInt32(MyColors(1)) Dim MyColor As Color = Color.FromArgb(red, green, blue) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Leaders dynamic_sysop Posted February 23, 2004 Leaders Posted February 23, 2004 dim the string as an array , eg: Dim MyString As String() = lstRGB.SelectedItem.Split(" ") '/// your values will be MyString(0) , MyString(1) and MyString(2) Edit: grr beaten to the post ;) :p Quote
DR00ME Posted February 23, 2004 Author Posted February 23, 2004 lol thx guys Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
DR00ME Posted February 23, 2004 Author Posted February 23, 2004 now it works like this: Dim MyArray() As String Dim MyString As String MyString = lstRGB.SelectedItem MyArray = MyString.Split(" "c) lblIndexSelect.BackColor = _ Color.FromArgb(CByte(MyArray(0)), CByte(MyArray(1)), CByte(MyArray(2))) is there any difference between CByte and Convert.ToByte ? Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.