Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. convert from one type to another

convert from one type to another

Scheduled Pinned Locked Moved Visual Basic
graphicshelpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WestSideRailways
    wrote on last edited by
    #1

    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.:)

    M 1 Reply Last reply
    0
    • W WestSideRailways

      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.:)

      M Offline
      M Offline
      MatrixCoder
      wrote on last edited by
      #2

      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.

      W 1 Reply Last reply
      0
      • M MatrixCoder

        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.

        W Offline
        W Offline
        WestSideRailways
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • W WestSideRailways

          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

          M Offline
          M Offline
          MatrixCoder
          wrote on last edited by
          #4

          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.

          W 1 Reply Last reply
          0
          • M MatrixCoder

            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.

            W Offline
            W Offline
            WestSideRailways
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • W WestSideRailways

              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

              C Offline
              C Offline
              ChandraRam
              wrote on last edited by
              #6

              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

              W 1 Reply Last reply
              0
              • C ChandraRam

                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

                W Offline
                W Offline
                WestSideRailways
                wrote on last edited by
                #7

                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.

                C 1 Reply Last reply
                0
                • W WestSideRailways

                  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.

                  C Offline
                  C Offline
                  ChandraRam
                  wrote on last edited by
                  #8

                  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

                  W 1 Reply Last reply
                  0
                  • C ChandraRam

                    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

                    W Offline
                    W Offline
                    WestSideRailways
                    wrote on last edited by
                    #9

                    ok then, i took your answer another way.... Still does not answer my question thou... I take it that it cannot be done.!!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups