Thaddy,
very nice.
Yeah, that "Insert" bugged me, too, and in my tests in VBA i actually did use "reverse" concatenation.
But i wanted to stay as close as possible to Jamie's original code, so... *shrug*
I was even thinking introducing a Flag as Function-Argument, something like "... var ZeroBased:Integer=1..."
along the lines of
{$mode objfpc}{$H+}
function DecodeGridLetterValue(aValue: ansistring; var ZeroBased:Integer=0): Qword;
var
c:AnsiChar;
begin
aValue := UpCase(aValue);// from system
Result := 0;
for C in AValue do
Result := Result * 26 + (Ord(C) - Ord('A'))+1; //Add 1 to get original Excel-Algorithm
If ZeroBased<>0 Then ZeroBased:=1;
Result:=Result-ZeroBased;
//Dec(Result); //Decrease by one at the end to get 0-based
end;
function EncodeGridLetterValue(aValue: Qword; var ZeroBased:Integer=0): ansistring;
var
Balance: integer;
begin
Result := '';// initialize
If ZeroBased<>0 Then ZeroBased:=1;
//We have to offset --> you pass "25" you expect "Z", you pass "26" you expect "AA"
AValue:=AValue+ZeroBased;
//This is the Algorithm to return the Original Excel-lettering 1-based
repeat
Balance := (Avalue-1) mod 26;
Result := char(Ord('A') + Balance) + Result; // do not use insert. Reverse the order and concat.
AValue := (AValue-Balance) div 26;
until AValue = 0;
end;
That way he could have both worlds