Solved

Converting from a String to a ColorConstant

Posted on 2002-07-22
6
768 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now