jjames
Programmer
- Mar 13, 2001
- 212
I need a function that will return a number which is an index into a array of color values. These colors represent a rating, Red = Bad, Yellow = Ok, Green = Good, etc. There are 7 possible values that can be returned. For purposes of illustration...
1 = Red
2 = Lt Red
3 = Redish Green
4 = Yellow
5 = Greenish Red
6 = Lt Green
7 = Green
My call to the function would look like this...
lngMin and lngMax are the range of values allowed. The minimum value at this time would always be 0 but the maximum value can be anything, 0 to 1, 0 to 3, 0 to 10, 0 to 230, etc.
The function itself may look like this...
So in this case where
lngMin = 0
lngMax = 10
lngValue = 4
GetColorIndex would return a 3
Value ColorIndex
0 = 1
1 - 2 = 2
3 - 4 = 3
5 = 4
6 - 7 = 5
8 - 9 = 6
10 = 7
or if
lngMin = 0
lngMax = 3
lngValue = 2
GetColorIndex would return a 5
Value ColorIndex
0 = 1
= 2
1 = 3
= 4
2 = 5
= 6
10 = 7
Thanks for any help, I've been looking at this problem off and on for days and just can't get my head around it.
1 = Red
2 = Lt Red
3 = Redish Green
4 = Yellow
5 = Greenish Red
6 = Lt Green
7 = Green
My call to the function would look like this...
Code:
lngMin = 0
lngMax = 10
lngValue = 4
lngColorIndex = GetColorIndex(lngMin, lngMax, lngValue)
lngMin and lngMax are the range of values allowed. The minimum value at this time would always be 0 but the maximum value can be anything, 0 to 1, 0 to 3, 0 to 10, 0 to 230, etc.
The function itself may look like this...
Code:
Private Function GetColorIndex(Min as Long, Max as Long, Value as Long) as long
if Value = Min then
GetColorIndex = 1 'Red
ElseIf Value = Max then
GetColorIndex = 7 'Green
else
'this is where I get stuck
'GetColorIndex = n
'At this point n cannot be 1 or 7
'Need to calculate rating based on range of values
'and the actual value
Endif
So in this case where
lngMin = 0
lngMax = 10
lngValue = 4
GetColorIndex would return a 3
Value ColorIndex
0 = 1
1 - 2 = 2
3 - 4 = 3
5 = 4
6 - 7 = 5
8 - 9 = 6
10 = 7
or if
lngMin = 0
lngMax = 3
lngValue = 2
GetColorIndex would return a 5
Value ColorIndex
0 = 1
= 2
1 = 3
= 4
2 = 5
= 6
10 = 7
Thanks for any help, I've been looking at this problem off and on for days and just can't get my head around it.