Results 1 to 5 of 5

Thread: Color Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    Question Color Problem

    HAI,

    i am in need to convert the string into long variable in vb 6.0
    for example : if we type green it should be converted into its equivalent rgb
    components

    can any one suggest urgent reply needed

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Color Problem

    Why not just use the RGB function or the VB color constants?

    ie:

    vb Code:
    1. Me.BackColor = vbGreen
    2.  
    3. Me.BackColor = RGB(0, 255, 0)

  3. #3
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Color Problem

    you can use vbGreen.

    vb Code:
    1. Private Sub Form_Load()
    2.     Shape1.FillColor = vbGreen
    3. End Sub

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Color Problem

    Something like this? But you'll have to manually enter all the different Colour possibilities

    Code:
    Private Type ColourList
        ColourName As String
        ColourValue As Long
    End Type
    Dim Colours(7) As ColourList
    Private Sub Form_Load()
        Colours(0) = SetColourInfo("Black", vbBlack)
        Colours(1) = SetColourInfo("Blue", vbBlue)
        Colours(2) = SetColourInfo("Cyan", vbCyan)
        Colours(3) = SetColourInfo("Green", vbGreen)
        Colours(4) = SetColourInfo("Magenta", vbMagenta)
        Colours(5) = SetColourInfo("Red", vbRed)
        Colours(6) = SetColourInfo("White", vbWhite)
        Colours(7) = SetColourInfo("Yellow", vbYellow)
        
        MsgBox GetColourLong("green")
    End Sub
    
    Private Function SetColourInfo(ColourName As String, ColourVal As Long) As ColourList
    SetColourInfo.ColourName = ColourName
    SetColourInfo.ColourValue = ColourVal
    End Function
    
    Private Function GetColourLong(StrName As String) As Long
    Dim C As Integer
        For C = 0 To UBound(Colours)
            If LCase(Colours(C).ColourName) = LCase(StrName) Then
                GetColourLong = Colours(C).ColourValue
                Exit For
            End If
        Next
    End Function

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    Re: Color Problem

    ok i resolved that problem thanks for ur reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width