No Problem.
You can use Math.Max but it only accepts 2 values to compare. Max compares multiple values and retuns the largest one.
This should do the trick :)
Structure CMYK
Dim C As Double
Dim M As Double
Dim Y As Double
Dim K As Double
End Structure
Structure RGB
Dim R As Double
Dim G As Double
Dim B As Double
End Structure
Private Function RGBtoCMYK(ByVal rgbIn As RGB) As CMYK
Dim cmykOut As CMYK
With rgbIn
.R = .R / 255
.G = .G / 255
.B = .B / 255
End With
Dim arr(2) As Double
arr(0) = rgbIn.R
arr(1) = rgbIn.G
arr(2) = rgbIn.B
With cmykOut
.K = 1 - arr.Max
.C = (1 - rgbIn.R - .K) / (1 - .K)
.M = (1 - rgbIn.G - .K) / (1 - .K)
.Y = (1 - rgbIn.B - .K) / (1 - .K)
End With
Return cmykOut
End Function
You can call the funtion usings something like
Dim colorIn As RGB
With colorIn
.R = 50
.G = 100
.B = 150
End With
Dim colorOut As CMYK = RGBtoCMYK(colorIn)