Solved

Converting from a String to a ColorConstant

Posted on 2002-07-22
6
793 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
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 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