Type mismatch error

Posted on 2007-10-08
Last Modified: 2008-01-09
Can someone tell me how I can get this to work.  I am getting a type mismatch error right now.

Public myForeColor As String
myForeColor = "&HFFFF&"

label1.ForeColor = myForeColor
Question by:jmsloan
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    this should work better:

    System.Drawing.ColorConverter cc = new System.Drawing.ColorConverter();
    label1.ForeColor = (System.Drawing.Color) cc.ConvertFromString("#FF0000");
    LVL 62

    Expert Comment

    by:Fernando Soto
    Hi jmsloan;

    ForColor is of type Color and not String. The following should do what you want.

            Public myForeColor As Color
            myForeColor = Color.FromArgb(255, 0, 255, 255)
            label1.ForeColor = myForeColor

    LVL 8

    Expert Comment

    forecolor is a system drawing color.

    try playing with
    scColor As New System.Drawing.ColorConverter


    LVL 3

    Author Comment

    I forgot to mention I am using VB6
    LVL 142

    Accepted Solution

    with vb6, just do it like this:
    label1.ForeColor = val(myForeColor)
    LVL 62

    Expert Comment

    by:Fernando Soto
    I think this is correct

            Public myForeColor As Long
            '                            RED, GREEN, BLUE  
            myForeColor = RGB(0,   255,      255)
            label1.ForeColor = myForeColor

    This value HFFFF is the same as H00FFFF = RED = 0, GREEN = 255,  BLUE = 255

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now