Henry Olive 5 Posted June 23, 2022 Good Day, MyCode in Database = VARCHAR(20) MyCode could be (120 or 250) like 3 digit Integer, or (200.001 or 600.010) there is a dot between numbers, or (500.005.0010 or 100.010.1500) there are 2 dots between numbers I need to Increase MyCode by 1 that is if MyCode = 100 then requested result = 101 if MyCode = 300.001 then requested result = 300.002 if MyCode = 600.005.0010 then requested result = 600.005.0011 How can i do that ? Thank You Share this post Link to post
Sherlock 663 Posted June 23, 2022 I would suggest to look up TryStrToInt. But that is just the beginning. What happens if you add 1 to 999.9999? Are there rules for those grouping dots? If the dots are always at the same place you could remove them before conversion and put them back in after your math and reconversion to string. Share this post Link to post
SwiftExpat 65 Posted June 23, 2022 (edited) 34 minutes ago, Henry Olive said: 600.005.0011 split the string based on the delimiter for the last string in the list, ('0011') convert to integer (11) and increment (12) convert the int back to a string ('12') compare the lengths and then loop to add in the padding zeros ('0012') concate the list back to 1 string Edited June 23, 2022 by SwiftExpat note to concat Share this post Link to post
PeterBelow 238 Posted June 23, 2022 2 hours ago, Henry Olive said: Good Day, MyCode in Database = VARCHAR(20) MyCode could be (120 or 250) like 3 digit Integer, or (200.001 or 600.010) there is a dot between numbers, or (500.005.0010 or 100.010.1500) there are 2 dots between numbers I need to Increase MyCode by 1 that is if MyCode = 100 then requested result = 101 if MyCode = 300.001 then requested result = 300.002 if MyCode = 600.005.0010 then requested result = 600.005.0011 How can i do that Do it on the string itself, like you learned addition in school. function incrementID(const aID: string):string; var ch: Char; N: Integer; begin Result := aID; N:= Length(Result); while N > 0 do begin ch := Result[N]; case ch of '0'..'8': begin Result[N] := Succ(ch); Break; end; '9': begin Result[N] := '0'; Dec(N); end; '.': Dec(N); else raise Exception.CreateFmt('Invalid character "%s" in ID "%s" at position %d.', [ch, aID, N]); end; {case ch} end; {while} end; 2 Share this post Link to post
Henry Olive 5 Posted June 23, 2022 Thank You Sherlock, SwiftExpat Thank You SO MUCH Peter Share this post Link to post
mvanrijnen 123 Posted June 23, 2022 (edited) [wrong topic] Edited June 23, 2022 by mvanrijnen Share this post Link to post
Serge_G 87 Posted June 23, 2022 (edited) Hi, yes you can Split procedure TForm23.Button1Click(Sender: TObject); var S : TArray<String>; begin S:=Edit3.Text.Split(['.']); S[length(S)-1]:=Format('%.3d',[(StrToInt(S[Length(S)-1])+1)]); Edit3.Text:=String.Join('.',S); end; Edited June 23, 2022 by Serge_G Share this post Link to post
Fr0sT.Brutal 900 Posted June 23, 2022 Quote Edit3.Text:=String.Join('.',[S[0],S[1],S[3]]); Edit3.Text:=String.Join('.',S); ? 1 Share this post Link to post
Serge_G 87 Posted June 23, 2022 (edited) @Fr0sT.Brutal, code was edited during your post. Just a thing, this MyCode = 600.005.0010 then requested result = 600.005.0011 should not work you have to manage a way to have the good formatstring something like procedure TForm23.Button1Click(Sender: TObject); var S : TArray<String>; fmt : string; begin S:=Edit3.Text.Split(['.']); fmt:='%.'+Length(S[Length(S)-1]).tostring+'d'; S[length(S)-1]:=Format(fmt,[(StrToInt(S[Length(S)-1])+1)]); Edit3.Text:=String.Join('.',S); end; Edited June 23, 2022 by Serge_G 1 Share this post Link to post