Following solution in Delphi, I highlight that Edit1 and Edit2 expect a valid string, with the format:
ggº mm' ss"
procedure TForm1.Button1Click(Sender: TObject);
function GetValorNumerico(const P_Texto: string; const P_Caracter: Char): Integer;
begin
case P_Caracter of
'º': Result := StrToInt(Trim(Copy(P_Texto, 1, Pos(P_Caracter, P_Texto)-1)));
'''': Result := StrToInt(Trim(Copy(P_Texto, Pos('º', P_Texto)+2, 2)));
'"': Result := StrToInt(Trim(Copy(P_Texto, Pos('''', P_Texto)+2, 2)));
end;
end;
var
W_Graus1: integer;
W_Minutos1: integer;
W_Segundos1: integer;
W_Graus2: integer;
W_Minutos2: integer;
W_Segundos2: integer;
W_Graus3: integer;
W_Minutos3: integer;
W_Segundos3: integer;
begin
W_Graus1 := GetValorNumerico(Edit1.Text, 'º');
W_Minutos1 := GetValorNumerico(Edit1.Text, '''');
W_Segundos1 := GetValorNumerico(Edit1.Text, '"');
W_Graus2 := GetValorNumerico(Edit2.Text, 'º');
W_Minutos2 := GetValorNumerico(Edit2.Text, '''');
W_Segundos2 := GetValorNumerico(Edit2.Text, '"');
if W_Segundos1 < W_Segundos2 then
begin
Dec(W_Minutos1);
Inc(W_Segundos1, 60);
end;
W_Segundos3 := W_Segundos1 - W_Segundos2;
if W_Minutos1 < W_Minutos2 then
begin
Dec(W_Graus1);
Inc(W_Minutos1, 60);
end;
W_Minutos3 := W_Minutos1 - W_Minutos2;
W_Graus3 := W_Graus1 - W_Graus2;
Label1.Caption := Format('%dº %d'' %d"', [W_Graus3, W_Minutos3, W_Segundos3]);
end;
Hi Melissa had computer problem and saw only today (May 1)
– user101552
Hi Melissa my name Alessandro I had computer problem and I saw your post only today (May 1) grateful for the code I will test it. Thank you
– user101552