Solved

commonDialog Show color

Posted on 2001-06-21
34
495 Views
Last Modified: 2008-02-01
i use Visual Interdev to create a CommonDialog box to display color box for me to choose color.
but i found that the color i choosed is not same as the color display. (Not all color, but some)
So i hope anyone can help me. Thanks alot.

Below is the source code.

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub button1_onclick

     CommonDialog1.ShowColor
     text1.style.backgroundColor= CommonDialog1.Color
     
     
End Sub

-->
</SCRIPT>
</HEAD>
<BODY>

<P>
<OBJECT id=CommonDialog1 classid=clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB><PARAM NAME="_ExtentX" VALUE="847"><PARAM NAME="_ExtentY" VALUE="847"><PARAM NAME="_Version" VALUE="393216"><PARAM NAME="CancelError" VALUE="0"><PARAM NAME="Color" VALUE="0"><PARAM NAME="Copies" VALUE="1"><PARAM NAME="DefaultExt" VALUE=""><PARAM NAME="DialogTitle" VALUE=""><PARAM NAME="FileName" VALUE=""><PARAM NAME="Filter" VALUE=""><PARAM NAME="FilterIndex" VALUE="0"><PARAM NAME="Flags" VALUE="0"><PARAM NAME="FontBold" VALUE="0"><PARAM NAME="FontItalic" VALUE="0"><PARAM NAME="FontName" VALUE=""><PARAM NAME="FontSize" VALUE="8"><PARAM NAME="FontStrikeThru" VALUE="0"><PARAM NAME="FontUnderLine" VALUE="0"><PARAM NAME="FromPage" VALUE="0"><PARAM NAME="HelpCommand" VALUE="0"><PARAM NAME="HelpContext" VALUE="0"><PARAM NAME="HelpFile" VALUE=""><PARAM NAME="HelpKey" VALUE=""><PARAM NAME="InitDir" VALUE=""><PARAM NAME="Max" VALUE="0"><PARAM NAME="Min" VALUE="0"><PARAM NAME="MaxFileSize" VALUE="260"><PARAM NAME="PrinterDefault" VALUE="1"><PARAM NAME="ToPage" VALUE="0"><PARAM NAME="Orientation" VALUE="1"></OBJECT>
<INPUT id=text1 name=text1></P>
<P><INPUT id=button1 type=button value=Button name=button1></P>

</BODY>
</HTML>
0
Comment
Question by:chencc77
  • 17
  • 15
  • 2
34 Comments
 
LVL 20

Expert Comment

by:Silvers5
ID: 6213483
In cases I encounered that IE browsers don't show the selected colors but a close match... I thought it might be that I have a pattern of 24bit colors (FFFFFF) and my display settings are set to 16 bit or less.. this might occure..
0
 

Author Comment

by:chencc77
ID: 6213565
i found that the color box use 'long' numeric to identify the color. So how am i going to solve this problem??
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6213600
yes.. 24 bit value.. 16777215 = FFFFFF hex

what are your entered values?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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 26

Expert Comment

by:EDDYKT
ID: 6214068
I found the red and blue color has been change position

try this


Function RGBX(red, green, blue)
     
    On Error Resume Next
     RGBX = RGB(blue, green, red)
end Function


function GetRed(color)
     
    On Error Resume Next
     GetRed = color And &HFF
end Function

function GetGreen(color)
     
    On Error Resume Next
     GetGreen = ((color And &HFF00) / &H100) And &HFF
end Function

function GetBlue(color)
     
    On Error Resume Next
     GetBlue = ((color And &HFF0000) / &H10000) And &HFF
end Function


text1.style.backgroundColor = RGBX(getblue(color), getgreen(color), getred(color))
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 6214074
OOhs where color is

Dim color
color = CommonDialog1.Color


0
 

Author Comment

by:chencc77
ID: 6216644
hi EDDYKT,
i have edit the code, but i found it show all black color.


<%@ Language=VBScript %>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Dim color

Sub button1_onclick

CommonDialog1.ShowColor
color = CommonDialog1.Color
msgbox color
msgbox RGBX(getblue(color), getgreen(color), getred(color))
text1.style.backgroundColor = RGBX(getblue(color), getgreen(color), getred(color))

End Sub



Function RGBX(red, green, blue)
    msgbox "rGBX"
   On Error Resume Next
    RGBX = RGB(blue, green, red)
end Function


function GetRed(color)
   
   On Error Resume Next
    GetRed = color And &HFF
end Function

function GetGreen(color)
   
   On Error Resume Next
    GetGreen = ((color And &HFF00) / &H100) And &HFF
end Function

function GetBlue(color)
   
   On Error Resume Next
    GetBlue = ((color And &HFF0000) / &H10000) And &HFF
end Function



-->
</SCRIPT>
</HEAD>

<BODY>

<P>&nbsp;</P>
<INPUT id=text1 name=text1>
<INPUT id=button1 type=button value=Button name=button1>
<OBJECT id=CommonDialog1 classid=clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB><PARAM NAME="_ExtentX" VALUE="847"><PARAM NAME="_ExtentY" VALUE="847"><PARAM NAME="_Version" VALUE="393216"><PARAM NAME="CancelError" VALUE="0"><PARAM NAME="Color" VALUE="0"><PARAM NAME="Copies" VALUE="1"><PARAM NAME="DefaultExt" VALUE=""><PARAM NAME="DialogTitle" VALUE=""><PARAM NAME="FileName" VALUE=""><PARAM NAME="Filter" VALUE=""><PARAM NAME="FilterIndex" VALUE="0"><PARAM NAME="Flags" VALUE="0"><PARAM NAME="FontBold" VALUE="0"><PARAM NAME="FontItalic" VALUE="0"><PARAM NAME="FontName" VALUE=""><PARAM NAME="FontSize" VALUE="8"><PARAM NAME="FontStrikeThru" VALUE="0"><PARAM NAME="FontUnderLine" VALUE="0"><PARAM NAME="FromPage" VALUE="0"><PARAM NAME="HelpCommand" VALUE="0"><PARAM NAME="HelpContext" VALUE="0"><PARAM NAME="HelpFile" VALUE=""><PARAM NAME="HelpKey" VALUE=""><PARAM NAME="InitDir" VALUE=""><PARAM NAME="Max" VALUE="0"><PARAM NAME="Min" VALUE="0"><PARAM NAME="MaxFileSize" VALUE="260"><PARAM NAME="PrinterDefault" VALUE="1"><PARAM NAME="ToPage" VALUE="0"><PARAM NAME="Orientation" VALUE="1"></OBJECT>

</BODY>
</HTML>
0
 

Author Comment

by:chencc77
ID: 6216666
EDDYKT : i found the Getxxx function doesn't work.

Silvers5 : my display setting is 24bit - TRue Color, izit the display setting will effect it?? i found the IE browser use the same color box, but it showed the exact color as i choosed. So wht was the reason there?? Thanks
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217460
Nahh.. this has nothing with the display then.. 1 min..
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217479
why such a turn.. simply remove all the other functions and leave this:

Sub button1_onclick

CommonDialog1.ShowColor
color = hex(CommonDialog1.Color)
text1.style.backgroundColor = "#" & color

End Sub



;o)
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217519
hmm same issue.. I'll do it another way.. 1 min..
0
 

Author Comment

by:chencc77
ID: 6217528
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
0
 

Author Comment

by:chencc77
ID: 6217534
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
0
 

Author Comment

by:chencc77
ID: 6217542
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217550
the dialogue box is returning the colors info blue green red instead of red green blue ..I'll fix you a code in 1 min..
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217567
Shake it baby ;o)


Sub button1_onclick

CommonDialog1.ShowColor
color = hex(CommonDialog1.Color)
color =  Right(color,2) & Mid(color,3,2) & left(color,2)
text1.style.backgroundColor = "#" & color
End Sub

0
 

Author Comment

by:chencc77
ID: 6217568
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217577
This issue was tricky! the dialogue box seemed to have a bug.. 100 extra points are nice :o)  jokin..
0
 

Author Comment

by:chencc77
ID: 6217585
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 

Author Comment

by:chencc77
ID: 6217589
no problems...  :>
need ur help.
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217598
I'll need to polish the code for bugs.. like if the color number is less than 6 digits.. or is 0
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217603
But the main issue is resolved.. colors are shown exactly as they are.. give me a minute for polishing..
0
 

Author Comment

by:chencc77
ID: 6217610
silver5 : not all color are fix. still got error.

 :(
0
 
LVL 20

Accepted Solution

by:
Silvers5 earned 300 total points
ID: 6217613
here's your final sub, check it:

Sub button1_onclick

CommonDialog1.ShowColor
msgbox CommonDialog1.Color
color = CommonDialog1.Color
if clng(color) = 0 then
color = "000000"
else
color = hex(color)
do while len(color) < 6
color = "0" & color
loop
end if
msgbox color
color =  Right(color,2) & Mid(color,3,2) & left(color,2)
text1.style.backgroundColor = "#" & color
End Sub
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217619
>silver5 : not all color are fix. still got error.

what color?
0
 

Author Comment

by:chencc77
ID: 6217626
silver5 : not all color are fix. still got error.

 :(
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217627
remove the msb boxes from the sub..
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217629
msg boxes
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217633
the last code I gave will take all colors.. the error you had is because of the colors that are less than 6 in hex length.. try it and report back
0
 

Author Comment

by:chencc77
ID: 6217648
silver5 : not all color are fix. still got error.

 :(
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217654
Chen.. what is the error? or your post is duplicated (you are on a slow connection?)
0
 

Author Comment

by:chencc77
ID: 6217659
silver5 : thank you very much, really appreciate ur help.

^_^  .  really nice to meet u here!!


from,
cc chen
0
 

Author Comment

by:chencc77
ID: 6217662
silver5 : yes, the msg is duplicated. u have solve all the problems...

0
 

Author Comment

by:chencc77
ID: 6217666
here's ur points
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6217676
You're welcome ;o)  I was glad to solve.. a bug! :o)

I posted comment to your other question that you can't use getred getgreen and getblue function.. your best way is to convert them to Hex and get the part you need using mid function..

rgrds
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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