Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog Control - Color Selector 1

Status
Not open for further replies.

tjtindal

Programmer
Mar 22, 2004
66
US
Is there anyway to use the common dialog control / color selector function and specify the red/green/blue it starts on instead of always just starting on black?
 
With CommonDialog1
.Flags = cdlCCRGBInit
.Color = YourColor
.ShowColor
End With

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Actually if it's a custom color you'll need to add the flag cdlCCFullOpen, such as:

With CommonDialog1
.Flags = cdlCCRGBInit + cdlCCFullOpen
.Color = RGB(0, 213, 200)
.ShowColor
End With


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
When combining binary flag values I normally use logical OR rather than arithmetic addition. It can avoid trappy stuff when you're doing combinations.

Compare:
myFlags = cdlCCRGBInit + cdlCCFullOpen ' yields 3
myOtherFlags = cdlCCRGBInit OR cdlCCFullOpen ' yields 3

At a later stage:
myNewFlags = myFlags + cdlCCFullOpen ' yields 5 - not what you want!
myOtherNewFlags = myOtherFlags OR cdlCCFullOpen ' yields 3 - still the right answer!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
>> When combining binary flag values I normally use logical OR rather than arithmetic addition

Very GOOD point!!!

there are some places that this can get you in trouble... such as modifying an existing flag value, or if one of your flags contains common bits of another flag...

use Or to Set a Flag:
Flags = Flags Or Flag

use And-Not to Clear a Flag
Flags = Flags And (Not Flag)

Never try to use And to add flags to a list...

Flag1 = 1 '0001
Flag2 = 2 '0010
Flag3 = 4 '0100

------------------------
Or Operator
Code:
MyFlags = Flag1 Or Flag2
    0001
 Or 0010
  = 0011 ...Right

Later...
Code:
MyFlags = MyFlags Or Flag2 Or Flag3
    0011
 Or 0010 ...0011
 Or 0100
  = 0111 ...Right

---------------------------
+ Operator
Code:
MyFlags = Flag1 + Flag2
    0001
  + 0010
  = 0011 'Right (With luck ;-)

Later...
Code:
MyFlags = MyFlags + Flag2 + Flag3
    0011
 Or 0010 ...0101 (1 carried over... 10 + 10 = 100)
 Or 0100
  = 1001 ...Wrong (1 carried over (again)... 100 + 100 = 1000)

---------------------------
And operator
Code:
MyFlags = Flag1 And Flag2
    0001
And 0010
  = 0000 ...Wrong (flags contain no common bit)

Later...
Code:
MyFlags = MyFlags And Flag2 And Flag3
    0011
And 0010 ...0010 (flags contain only 1 common bit)
And 0100
  = 0000 ...Wrong (flags contain no common bit)

----------------------------------------
You can, however, use And to check for a flag...
Code:
If myFlags And Flag2 Then...
    0011
And 0010
  = 0010 ...Right (Flag2 has common bit in myFlags)

However, it may not work like this for Flags w/ multiple bits...
Code:
FlagX = 3 '0011
Flags = 6 '0110
If Flags And FlagX Then...
    0011
And 0110
  = 0010 ...Wrong (Only 1 common bit in Flags)

But, you can do it like this...
Code:
If (Flags And FlagX) = FlagX Then

This Way, It must have all of the common bits to be true...

So, in closing... the + operator can be used in a few places but is a bad practice, when Or can be used in all places...

Have Fun, Be Young... Code BASIC
-Josh

cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top