Is there a function that converts a number to a Character-string like excel columns
- Code: Select all Expand view RUN
- 1 = A
2 = C
...
26 = Z
27 = AA
28 = AB
..
52 = AZ
53 = BA
..
1 = A
2 = C
...
26 = Z
27 = AA
28 = AB
..
52 = AZ
53 = BA
..
FUNCTION cGExcCol( nCol )
LOCAL cCol := "", nTmp
IF nCol > 26
nTmp := INT( nCol / 26 )
IF nTmp > 26
RETURN 0
ENDIF
cCol += CHR( ASC( "@" ) + nTmp )
ENDIF
nTmp := nCol % 26
IF nTmp > 0
cCol += CHR( ASC( "@" ) + ( nCol % 26 ) )
ELSE
cCol += "Z"
ENDIF
RETURN cCol
/*****************************************************************************/
FUNCTION nGExcCol( cCol )
LOCAL nPos := 0
cCol := ALLTRIM( cCol )
IF .NOT. EMPTY( cCol )
IF LEN( cCol ) > 1
nPos := 26 * (ASC( LEFT( cCol, 1 ) ) - ASC( "@" ))
cCol := SUBSTR( cCol, 2 )
ENDIF
nPos += (ASC( LEFT( cCol, 1 ) ) - ASC( "@" ))
IF nPos > 230
nPos := 0
ENDIF
ENDIF
RETURN nPos
static Function MakeColAlphabet( nCol )
local cCol := ""
local nDigit
do while nCol > 0
nDigit := nCol % 26
if nDigit == 0
nDigit := 26
nCol -= 26
endif
cCol := Chr( nDigit + 64 ) + cCol
nCol := Int( nCol / 26 )
enddo
return cCol
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 68 guests