Re: increment
- From: "Steve Zimmelman" <skz@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 16 Feb 2006 11:02:35 -0500
I can think of a couple of ways.
//*** Not Tested ***
Function IncFieldText(AStr:String):String ;
var
sl :TStringList ;
NextNum : Integer ;
iTest,i : Integer ;
Begin
sl :TStringList.Create ;
Try
sl.Text := StringReplace(AStr,'/',#13#10,[rfReplaceAll]);
If (sl.Count>0) Then Begin
iTest := StrToIntDef(sl[sl.Count-1],-1);
If (iTest >= 0) Then Begin
NextNum := Inc(iTest);
Result := '' ;
For i := 0 To sl.Count-2 Do Begin
Result := Result + sl[i]+'/' ;
End;
Result := Result + FormatFloat('00000',NextNum)
End Else Begin
// Handle no number found to inc here.
End;
End Else Begin
// Handle no number found to inc here.
End;
Finally
sl.Free ;
End;
End;
or
Function IncFieldText(AStr:String):String ;
Var
i,iPos : Integer ;
sNum : String ;
Function IsDigit(ch: char): boolean;
begin
Result := ch in ['0'..'9'];
end;
Begin
iPos := -1 ;
For i := Length(AStr) Down To 1 Do Begin
// Find last non-digit character.
If Not IsDigit(AStr[i]) Then Begin
iPos := i+1 ;
Break ;
End;
End;
If iPos > 0 Then Begin
sNum := Copy(AStr,iPos,Length(AStr));
i := StrToIntDef(sNum,-1);
If i > 0 Then Begin
sNum := FormatFloat('00000',i);
Result := Copy(AStr,1,iPos-1)+sNum ;
End Else Begin
// Handle no number found to inc here.
End;
End Else Begin
// Handle no number found to inc here.
End;
End;
-Steve-
"raw" <r_kirui@xxxxxxxxxxx> wrote in message
news:43f44a44$1@xxxxxxxxxxxxxxxxxxxxxxxxx
am using ms access and delphi7. how can i increment a field which has
characters like DML/010/00001. i want to increment the last characters
.
- References:
- increment
- From: raw
- increment
- Prev by Date: Field captions from MS Access
- Next by Date: ADO with paradox
- Previous by thread: increment
- Next by thread: BetterADO and Delphi 2006
- Index(es):