OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 21-05-2007, 16:46
diwin
Guest
 
Posts: n/a
Default color conversion

Hi. I am using CD11

I use UserAssignEx to open the color selector dialog, and store the selection in a database. When I choose "red" in cmyk (0,100,100,0) , I get the number 1910234 stored in the data table. I don't know what format that is.

How do I then use this info to specify a uniform fill color? Once I get access the value from the recordset, rsDotInfo("dotColor"), do I convert it and how do I code it? Can I use something like s.Fill.UniformColor.CMYKAssign once it is converted?
Reply With Quote
  #2  
Old 21-05-2007, 17:05
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

Code:
Function ColorToString(clr As Color) As String
   Dim c0&, c1&, c2&, c3&, c4&, c5&, c6&, c7&
   clr.CorelScriptGetComponent c0, c1, c2, c3, c4, c5, c6, c7
   On Error Resume Next
   ColorToString = Join(Array(c0, c1, c2, c3, c4, c5, c6, c7), ":")
End Function

Function ColorAssignFromString(ByRef clr As Color, compStr As String) As Boolean
   Dim cc() As String
   On Error GoTo BadString
   cc = Split(compStr, ":")
   If clr Is Nothing Then Set clr = New Color
   If UBound(cc) < 7 Then ReDim Preserve cc(0 To 7)
   clr.CorelScriptAssign cc(0), cc(1), cc(2), cc(3), cc(4), cc(5), cc(6), cc(7)
   ColorAssignFromString = True
BadString:
End Function
usage:
Code:
dim s as string, с as color
--------------------- CONVERT TO STRING
set c=new color
if c.UserAssignEx then
   s=ColorToString(c)
........
endif
--------------------- ASSIGN FROM STRING
s=....from db.....
if not ColorAssignFromString (myShape.Fill.UniformColor, s) then 'error
..........

Last edited by wOxxOm; 21-05-2007 at 17:13.
Reply With Quote
  #3  
Old 21-05-2007, 17:50
diwin
Guest
 
Posts: n/a
Default

Thanks wOxxOm

Not too sure how to correctly implement it.

Below is the dblclick event of a text box. "Dot 1" is in the active layer.

Code:
Private Sub txtCommon3_Enter()

    Dim sh As Shape
    Dim s As Color
    sh = ActiveLayer.Shapes.FindShape("dot 1")
        If Not ColorAssignFromString(sh.Fill.UniformColor, s) Then  'error

End Sub
Reply With Quote
  #4  
Old 21-05-2007, 17:59
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

:-) s is a string (text) variable that holds color universal description, use F8 if unsure and look at variables and results of functions

Code:
Private Sub txtCommon3_Enter()
    dim myColorString as string
    Dim sh As Shape

    sh = ActiveLayer.Shapes.FindShape("dot 1")
    myColorString=......... ' do you get it from database? or what?

    if not sh is nothing then
        If Not ColorAssignFromString(sh.Fill.UniformColor, myColorString) Then  'error
           msgbox "Achtung!"
        endif
    endif
End Sub
of course database should hold string values generated by ColorToString function from my previous post
Reply With Quote
  #5  
Old 21-05-2007, 18:17
diwin
Guest
 
Posts: n/a
Default

Aah.

Good I got it.
Just one more blip. I still need to use the color, retrieved from the database, for a userform textbox backcolor.
Reply With Quote
  #6  
Old 21-05-2007, 18:27
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

you need to ensure the color is rgb:
Code:
'....convert to rgb
dim c as color
ColorAssignFromString c,DBstring
c.ConvertToRGB
textbox.BackColor=rgb(c.RGBRed, c.RGBGreen, c.RGBBlue)
where rgb is a builtin VBA function
Reply With Quote
  #7  
Old 21-05-2007, 18:37
diwin
Guest
 
Posts: n/a
Default

Vielen Dank again wOxxOm

It is working fine.
Reply With Quote
  #8  
Old 21-05-2007, 18:40
wOxxOm's Avatar
wOxxOm wOxxOm is offline
Senior Member
 
Join Date: Mar 2005
Posts: 836
Default

portions © 4vR by Alex :-)
Reply With Quote
  #9  
Old 22-05-2007, 20:55
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,941
Blog Entries: 4
Default

By the way, you can use the native Color to string conversion methods to convert any color object into a string you can store in a database and then you can recreate the color from the database.

For this, you just use Color.ToString method to get a string out of a color object and then you can use Application.CreateColor to get a color from a string (or if you have a color object you want to update just use Color.StringAssign method):


Code:
Dim c As New Color
If c.UserAssignEx() Then
    SaveInDatabase c.ToString()
End If
...

Code:
Dim s As String
Dim c As Color
s = GetFromDatabase()
Set c = Application.CreateColor(s)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 15:33.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com