Solved

Converting from a String to a ColorConstant

Posted on 2002-07-22
6
806 Views
Last Modified: 2010-05-18
Hi, I am reading values in from a comma-delimited text file.  One of these values is a Color (HC0C0C0 for example).  When I read the line, split by the commas, and set my ColorConstants variable = the String from the file (HC0C0C0) I get an error that says 'type mismatch.'  How can I conver the String to a ColorConstant?
Thanks,
Josh

This is the type and array where I am keeping the data from the file:
Private Type syntax
    Tag As String
    Bold As Boolean
    Color As ColorConstants
End Type
Dim mSyntax() As syntax

This is how I read in from the text file - the commented line is where the program fails:
    Dim i As Integer
    Dim OpenFile As Integer
    Dim strLine As String
    Dim strSplit() As String
   
    If Dir(FileName) <> "" Then
        mstrSyntaxDefinitionFile = FileName
        ReDim mSyntax(0)
        OpenFile = FreeFile
        Open mstrSyntaxDefinitionFile For Input As #OpenFile
        Do Until EOF(OpenFile)
            Line Input #OpenFile, strLine
            strSplit = Split(strLine, ",")
            mSyntax(UBound(mSyntax)).Tag = strSplit(0)
            mSyntax(UBound(mSyntax)).Bold = strSplit(1)
'            mSyntax(UBound(mSyntax)).Color = strSplit(2)
            ReDim Preserve mSyntax(UBound(mSyntax) + 1)
        Loop
        Close #OpenFile
        ReDim Preserve mSyntax(UBound(mSyntax) - 1)
    End If
0
Comment
Question by:jsm11482
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 20

Expert Comment

by:hes
ID: 7170391
Try changing it to
.Color = "&" & strSplit(2) & "&"
0
 
LVL 1

Accepted Solution

by:
HelixDaKat earned 50 total points
ID: 7170403
jsm11482

Convert the HC0C0C0 value to a long

OleColorVar = Clng("&" & <HexVal>)  

The "&" Must be appended to the H to allow the Clng
method to convert a hex value to a long. So if you only have C0C0C0 then you would need to append "&H" to it and then convert it to a long.

Hope this helps

HelixDaKat
0
 
LVL 1

Expert Comment

by:HelixDaKat
ID: 7170414
jsm11482

You actually don't need the CLNG on that line.
But for readablity it might be helpful.

HelixDaKat
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:rpai
ID: 7170431
This should work:-
mSyntax(UBound(mSyntax)).Color = "&" & Trim(strSplit(2))
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7170512
You could use the val function:
msgbox val("&" & "HC0C0C0")
0
 

Author Comment

by:jsm11482
ID: 7170892
Flawless.  Thank you!
-Josh
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

688 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