Solved

Converting from a String to a ColorConstant

Posted on 2002-07-22
6
801 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
Independent Software Vendors: 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

732 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