*+--------------------------------------------------------------------
*+
*+ Source Module => c:\hmg.3.4.4\0\Lotto\\LOTTO.PRG
*+
*+ Copyright(C) 1983-2021 by Auge & Ohr
*+
*+ Functions: Procedure MAIN()
*+ Function FindDupe()
*+ Function NumColor2RGB()
*+
*+ Reformatted by Click! 2.05.39 on Apr-20-2022 at 7:35 am
*+
*+--------------------------------------------------------------------
#include "HMG.CH"
#include "Common.ch"
STATIC aResult := {}
MEMVAR _HMG_SYSDATA
*+--------------------------------------------------------------------
*+
*+ Procedure MAIN()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE MAIN
LOCAL aData := { { "XXX", 53, 29, 22, 70, 39, 82, 75, 33, 2, 51, 9, 68, 2, 61, 19 }, ;
{ "KKK", 15, 21, 60, 38, 44, 36, 75, 53, 59, 81, 59, 65, 8, 14, 82 }, ;
{ "TTT", 54, 4, 56, 77, 79, 58, 20, 41, 43, 60, 81, 83, 43, 45, 66 } }
LOCAL nRowMax := LEN( aData )
LOCAL nColMax
LOCAL ii, jj, nNum, nPosi, nNumColor
LOCAL nCount := 0
LOCAL aJustify := {}
LOCAL aBColors := {}
// read aData and add Number to aResult
ii := 1
FOR ii := 1 TO nRowMax
jj := 2
nColMax := LEN( aData[ ii ] )
FOR jj := 2 TO nColMax
nNum := aData[ ii ] [ jj ]
nPosi := ASCAN( aResult, { | e | e[ 1 ] = nNum } )
IF nPosi > 0
// increase Counter
aResult[ nPosi ] [ 2 ] := aResult[ nPosi ] [ 2 ] + 1
ELSE
// {Number,Counter,Color}
AADD( aResult, { nNum, 1, 0 } )
ENDIF
NEXT
NEXT
// add for each Column
ii := 1
FOR ii := 1 TO nColMax
AADD( aJustify, GRID_JTFY_LEFT )
AADD( aBColors, { || FindDupe() } )
NEXT
// sort Result
ASORT( aResult,,, { | aX, aY | aX[ 1 ] < aY[ 1 ] } )
// set Color when "dupe"
nNumColor := 600000
nCount := 0
ii := 1
FOR ii := 1 TO LEN( aResult )
IF aResult[ ii ] [ 2 ] > 1
nCount ++
aResult[ ii ] [ 3 ] := NumColor2RGB( nNumColor * nCount )
ENDIF
NEXT
DEFINE WINDOW Form_1 ;
AT 0, 0 ;
WIDTH 800 ;
HEIGHT 400 ;
MAIN
@ 10, 0 GRID Grid_1 ;
WIDTH 800 ;
HEIGHT 330 ;
HEADERS { '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' } ;
WIDTHS { 31, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50 } ;
ITEMS aData ;
CELLNAVIGATION ;
DYNAMICBACKCOLOR aBColors ;
JUSTIFY aJustify
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
RETURN
*+--------------------------------------------------------------------
*+
*+ Function FindDupe()
*+
*+ Called from ( lotto.prg ) 1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION FindDupe()
LOCAL nPosi
LOCAL bColor := {255,255,255}
LOCAL nCellValue
// these Variable are avaiable for GRID
LOCAL CellRowIndex := This.CellRowIndex
LOCAL CellColIndex := This.CellColIndex
LOCAL CellValue := This.CellValue
nCellValue := VAL( CellValue )
nPosi := ASCAN( aResult, { | e | e[ 1 ] = nCellValue } )
IF nPosi > 0
IF aResult[ nPosi ] [ 2 ] > 1
bColor := aResult[ nPosi ] [ 3 ]
ENDIF
ENDIF
RETURN bColor
*+--------------------------------------------------------------------
*+
*+ Function NumColor2RGB()
*+
*+ Called from ( lotto.prg ) 1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
FUNCTION NumColor2RGB( nColor )
LOCAL aRetVal
DEFAULT nColor TO - 1
IF nColor == - 1
aRetVal := { NIL, NIL, NIL }
ELSE
aRetVal := { GetRed( nColor ), GetGreen( nColor ), GetBlue( nColor ) }
ENDIF
RETURN aRetVal
*+ EOF: LOTTO.PRG