Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

commonDialog Show color

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
chencc77
Asked:
chencc77
  • 17
  • 15
  • 2
1 Solution
 
Michel SakrCommented:
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
 
chencc77Author Commented:
i found that the color box use 'long' numeric to identify the color. So how am i going to solve this problem??
0
 
Michel SakrCommented:
yes.. 24 bit value.. 16777215 = FFFFFF hex

what are your entered values?
0
Independent Software Vendors: 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!

 
EDDYKTCommented:
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
 
EDDYKTCommented:
OOhs where color is

Dim color
color = CommonDialog1.Color


0
 
chencc77Author Commented:
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
 
chencc77Author Commented:
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
 
Michel SakrCommented:
Nahh.. this has nothing with the display then.. 1 min..
0
 
Michel SakrCommented:
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
 
Michel SakrCommented:
hmm same issue.. I'll do it another way.. 1 min..
0
 
chencc77Author Commented:
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
0
 
chencc77Author Commented:
silver5 : can u try my code?? really there are some color that display different color from wht i choose.
0
 
chencc77Author Commented:
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 
Michel SakrCommented:
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
 
Michel SakrCommented:
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
 
chencc77Author Commented:
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 
Michel SakrCommented:
This issue was tricky! the dialogue box seemed to have a bug.. 100 extra points are nice :o)  jokin..
0
 
chencc77Author Commented:
silver5 : they are a error if use ur suggestion.

hex(0) = 0

no this color

:>
0
 
chencc77Author Commented:
no problems...  :>
need ur help.
0
 
Michel SakrCommented:
I'll need to polish the code for bugs.. like if the color number is less than 6 digits.. or is 0
0
 
Michel SakrCommented:
But the main issue is resolved.. colors are shown exactly as they are.. give me a minute for polishing..
0
 
chencc77Author Commented:
silver5 : not all color are fix. still got error.

 :(
0
 
Michel SakrCommented:
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
 
Michel SakrCommented:
>silver5 : not all color are fix. still got error.

what color?
0
 
chencc77Author Commented:
silver5 : not all color are fix. still got error.

 :(
0
 
Michel SakrCommented:
remove the msb boxes from the sub..
0
 
Michel SakrCommented:
msg boxes
0
 
Michel SakrCommented:
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
 
chencc77Author Commented:
silver5 : not all color are fix. still got error.

 :(
0
 
Michel SakrCommented:
Chen.. what is the error? or your post is duplicated (you are on a slow connection?)
0
 
chencc77Author Commented:
silver5 : thank you very much, really appreciate ur help.

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


from,
cc chen
0
 
chencc77Author Commented:
silver5 : yes, the msg is duplicated. u have solve all the problems...

0
 
chencc77Author Commented:
here's ur points
0
 
Michel SakrCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 17
  • 15
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now