Get a color name from any RGB combination?

Discussion in 'Excel Programming' started by Charlotte E., Apr 25, 2014.

  1. Charlotte E.

    GS Guest

    Not for OCXs, but DLLs should still be possible so long as
    'LoadLibrary' is available!
    It takes a bit more code to implement, but still requires its library
    to be registered. This is why I did my initial listbox-based dataform
    way back before UAC days and dropped support for mscomctl.ocx. I see,
    though, that similar libs ship as DLLs in recent versions of Windows
    and so may be worth re-exploring use of the listview!!

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 30, 2014
    #21
    1. Advertisements

  2. Charlotte E.

    Peter T Guest

    There is a ptrSafe version of LoadLibrary. So are you saying with RegFree
    you can use a VB6 aX dll in Office 64 and call it from VBA, as a ComAddin
    too?
    FWIW the mscomctl treeview has been adapted to VBA, can also use that for a
    simple listview that's used for the only reason you can include add an icon
    to the item.

    Regards,
    Peter T
     
    Peter T, Apr 30, 2014
    #22
    1. Advertisements

  3. Charlotte E.

    GS Guest

    Not sure about that because I expect the DLL needs to be x64. I don't
    have MSO x64 installed and so can't say. Perhaps you can ask Rob Bovey
    about this.

    Also, Olaf Schmidt provided the reg-free stuff for VBA and so you can
    ask him about MSO x64 in the classic VB forums. Note that this would be
    'OT'!
    Yes, I've seen that project but not tried it. I don't see how a
    treeview can also be used as a listview (or am I misunderstanding you),
    but I can do similar as both with my Spread.ocx. Again, though, it
    needs to be registered and so is not an option for VBA projects that
    need to be reg-free. (My apps are 100% portable and so MUST be
    reg-free) Otherwise, I have no issue installing/registering
    mscomctl.ocx. (I do plan to investigate using the newer DLL reg-free,
    though!)

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 30, 2014
    #23
  4. Charlotte E.

    Peter T Guest

    snip
    But can't compile a dll as 64bit, 32bit only. It's not Win64 that's the
    problem but Office64.
    Well not OT over there I assume! But I guess this is getting OT here
    already.
    Perhaps you might find the demo file that acts as an extended 'Project
    Explorer' handy!
    If the listview only contains a single column it has the same appearance and
    in effect functionality as a treeview that has multiple root nodes but no
    branches. Only reason to use a listview in such a case is for it's
    capability to add icons to items, as can do with a treeview.

    Regards,
    Peter T
     
    Peter T, Apr 30, 2014
    #24
  5. Charlotte E.

    GS Guest

    MSOx64 uses VBA7 for both 32/64 bit versions. This is not an issue!

    MSOx64 needs x64 DLLs AFAIK! That excludes using VB6 DLLs all
    together!!
    Ah! So it's the other way around; using listview as a treeview! I don't
    think the icon factor makes this worth the trouble for displaying data
    in a VBA userform.

    Please have a look at my listbox-based example when I'm done with it.
    Though Charlotte's usage only includes 4 fields of data, it can handle
    as many fields as a listbox max ColumnCount. This should be more than
    ample for a database solution that's flat-table text file based, and
    uses standard VB file I/O functions. IMO, that's as simple as it gets
    for working with smaller amounts of data. If it does grow large it can
    be easily 'dumped' into a SQLite db file and worked with via ADODB.

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 30, 2014
    #25
  6. Charlotte E.

    GS Guest

    Typo...

    MSO (since v2010) uses VBA7 for both 32/64 bit versions. This is not
    an issue!
    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 30, 2014
    #26
  7. Charlotte E.

    Peter T Guest

    No, use a treeview to resemble a listview, albeit for the limited purpose I
    described (and can't use aX/ocx controls)
    Can you point me to where it is (or again if as I assume it's linked
    somewhere in this long thread!)

    Regards,
    Peter T
     
    Peter T, Apr 30, 2014
    #27
  8. Charlotte E.

    GS Guest

    I'll be posting a download link (in this thread) for Charlotte *when
    I'm done with it*! (As I said, I couldn't find my original project so
    I'm redoing it from scratch)

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 30, 2014
    #28
  9. Charlotte E.

    Charlotte E. Guest

    Wow, I'd really started something here, haven't I? :)

    Really looking forward to your solution...
    ....the solution I'm trying to implement is to look up the individual RGB
    values, within the function itself - not 'smart' or pretty, but it is as
    fast as my skills will take me :)


    Thanks for all your inputs ans suggestions.

    CE


     
    Charlotte E., May 1, 2014
    #29
  10. Charlotte E.

    GS Guest

    What's important is that your solutions meets your needs!

    Since I don't have a need for this, I decided to make a generic utility
    named "Color Name Manager" that has the following features:

    allows you to add, edit, remove, and rename color name data;
    uses a comma delimited text file as its data storage;
    manages data with standard VB file I/O functions and arrays;
    is dialog based;
    creates its own menuitem;
    has task specific context management for user action controls;
    has a simple help system;
    finds RGB values for a given name;
    finds (existing) names for RGB values;

    It's an XLS with its 'IsAddin' property set True so it's hidden when
    open, but could be saved as XLA if desired. On first startup it
    notifies user of menuitem location in both early/late versions. Also,
    the VBA project (2 userforms, 2 modules) is accessible for modifying.

    I still have the Rename feature to finish plus write the Help text.
    Sorry it's taking longer than initially expected, but I seem to have
    discarded my initial listbox based data form sample and so had to start
    from scratch!<g> I'll keep pluging away at it between other obligations
    so it gets done sooner than later, and 'off my plate' for now. Perhaps
    we can swap projects<g>?

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, May 1, 2014
    #30
  11. Charlotte E.

    Peter T Guest

    Wow, all that for a simple colour match algorithm, and you said I added too
    much fluff! <vbg>

    Charlotte, if all you want to do is get the name of the colour that best
    matches your RGB see the example I included in my second post in this
    thread. It does exactly that using a simple "linear" calculation and
    replicates the javascript demo you referred to. It should be straightforward
    to adapt to your requirements.

    Regards,
    Peter T
     
    Peter T, May 1, 2014
    #31
  12. Charlotte E.

    GS Guest

    Wow, all that for a simple colour match algorithm, and you said I
    It's not a simple colour match algorithm!
    The development of this utility was inspired by your explanation of the
    time/effort you put into your project!

    There's no 'fluff' in my project; it just reflects its name in terms of
    features which fit what the name implies. It's being released as a
    'finished product' and so requires the effort necessary to that, IMO!
    It also writes the data to a worksheet named range and so can be used
    in a lookup formula if desired.

    What do you think a "Color Name *Manager*" utility should do?<g>

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, May 1, 2014
    #32
  13. Charlotte E.

    GS Guest

    Just curious, Peter, about where you are located having used this
    spelling...

    colour

    ...as I'm located in eastern Ontario, Canada but I use/speak enUS!

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, May 1, 2014
    #33
  14. Charlotte E.

    Peter T Guest

    Sorry I misunderstood, read it as all intended as a solution for Charlotte's
    Q
    There's no simple answer because it depends on peoples' objectives, and with
    colour match would probably be diverse. But like anything as a minimum a
    means to input and store data, input the query, process, and output, all
    with a suitable UI.

    There could be more than one list of colours, typically they range from as
    few as 40 to 1000+ colours. Maybe provide links to samples.

    A sheet is ideal for colours because you can store all the various
    attributes (RGB, Hex, HSL, name, etc) in cells and display each colour (in
    2003 coloured shapes as cells can only display 56 colours). Or for display
    only could also show each colour in a form in a variety of ways and retrieve
    from elsewhere.

    Input the colour to match, consider how, or maybe a coloured pixel 'picked'
    from the screen.

    Output the matched colour, its name and specs, to the form, perhaps to the
    clipboard too.

    As I mentioned my old app included a colour match utility as a small feature
    of a much larger range of colour related stuff.

    Regards,
    Peter T
     
    Peter T, May 1, 2014
    #34
  15. Charlotte E.

    Peter T Guest

    UK, ie English-English!
     
    Peter T, May 1, 2014
    #35
  16. Charlotte E.

    GS Guest

    Nice! How do you like living in the midst of all that UK history?

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, May 1, 2014
    #36
  17. Charlotte E.

    GS Guest

    There's no simple answer because it depends on peoples' objectives,
    And so is why I'm putting all the effort into it as a finished product!
    It's just displaying RGB as BackColor of a label. The code verifies if
    a new entry (or edited listitem) already has the RGB values OR name
    entered.

    I found this was a needed feature since Charlotte's link color names
    list has, for example, both "Aqua" and "Cyan" with the same RGB values.
    Thus I've 'removed' "Cyan" for now since it's a standard color. (the
    list should only have non-standard names to start with, IMO, leaving
    inclusions up to the end user)

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, May 1, 2014
    #37
  18. Charlotte E.

    Peter T Guest

    Why only non standard names, isn't that for the user to decide. If there are
    duplicates maybe return both, eg return "Aqua = Cyan". Indeed it's not
    unusual for colour lists to include 2+ names that refer to the same RGB, and
    in the case of this list there are are many duplicates besides cyan.
     
    Peter T, May 1, 2014
    #38
  19. Charlotte E.

    Peter T Guest

    Old!

    Only kidding, I appreciate having a sense of history around. Not always
    though, I arrived once in one particular country in the middle of troubles
    and asked a local to explain the background, and was told "need to go back
    3500 years and work forwards to begin to understand..." it took a long time!
    (too OT for here)
     
    Peter T, May 1, 2014
    #39
  20. Charlotte E.

    GS Guest

    As you say, it's up to the user to decide. I'm talking about the
    initial startup list I provide with the utility. *I prefer* to not
    include standard colors already in the standard palette. Thus users can
    add them if they want them included in the db, and/or
    edit/remove/rename existing colors to their liking! The intent is to
    supply a 'starter list' only. (I'm just treating it as 'dummy
    data'!<g>)

    The reason is that we all see the standard colors differently, so how
    Red appears to me doesn't necessarily match how it appears to you.
    Custom named RGB values are already how that respective color appears
    someone else, not necessarily how it appears to the user of this
    utility(IMO).

    I haven't deliberately looked for other duplicates because that's not
    on my agenda. This I'm leaving up to the user! If a matching name
    and/or RGB is encountered the user is notified and prompted for how
    they want to handle their input values when adding/editing data.

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, May 1, 2014
    #40
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.