Help with Stephen Lebans code

N

NevilleT

I am out of my depth in this code from Stephen Lebans and need some help. I
want to pick a colour and return an RGB code. Stephen has the following
sample.

Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" _
(pChoosecolor As COLORSTRUC) As Long

Public Function aDialogColor(prop As Property) As Boolean
Dim x As Long, CS As COLORSTRUC, CustColor(16) As Long


CS.lStructSize = Len(CS)
CS.hwnd = hWndAccessApp
CS.rgbResult = Nz(prop.Value, 0)
CS.Flags = CC_SOLIDCOLOR Or CC_RGBINIT
CS.lpCustColors = String$(16 * 4, 0)
x = ChooseColor(CS)
If x = 0 Then
' ERROR - use Default White
prop = RGB(255, 255, 255) ' White
aDialogColor = False
Exit Function
Else
' Normal processing
prop = CS.rgbResult
End If
aDialogColor = True
End Function
'*********** Code End ***********

' If you want this Function to simply Return
' the Value of the Color the user selected
' from the Dialog just change the Function
' Declaration in modColorPicker to something like:
'Public Function DialogColor(ctl As Control) As Long
' Remember to add the line of code at the
' end of the Function
'DialogColor = CS.rgbResult
' Then call it from your Form with code like:

'***Code Start
'Private Sub CmdChooseBackColor_Click()
' Pass the TextBox Control to the function
'Me.textCtl.BackColor = DialogColor(Me.textCtl)
'End Sub

My problem is I cannot work out what he means in the comments.
change the Function
' Declaration in modColorPicker to something like:
'Public Function DialogColor(ctl As Control) As Long

If I change aDialogColour to
Public Function DialogColor(ctl as Control) as Long
there are a few undeclared variables. I am sure this is not what he means
but cannot work it out. Can someone help?
 
K

KC-Mass

I believe he means

Replace this line
Public Function aDialogColor(prop As Property) As Boolean

With this line
Public Function DialogColor(ctl As Control) As Long

Also
Replace this line
aDialogColor = True

With this line
DialogColor = CS.rgbResult

Regards

Kevin
 
N

NevilleT

Thanks Kevin. Got that far but the problem is that prop is not declared. I
can declare it but the line
CS.rgbResult = prop.Value
will fail as prop is null. Will continue to do some digging and see if I
can work it out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top