Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting from a String to a ColorConstant

Posted on 2002-07-22
6
Medium Priority
?
830 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 200 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses

610 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