Autor Beitrag
discmix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Do 08.05.03 15:05 
Hallo,

ich lese aus einer DB ein Wert aus dem letzten Datensatz. Dieser Wert ist ein alphanumerischer Wert.
BSP: Tomy001 o. REG005ABC

Wie kann ich diesen Wert erhöhen?
BSP aus Tomy001 wird Tomy002
aus REG 005ABC wird REG005ABD wobei natuerlich bei Z der
vorletzte Buchstabe ebenfalls erhöht werden muss usw.

Hat jemand einen Tip?

Danke
DiscMix
ase
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 203

Gentoo, Windows 9X, ME, 2k, NT, XP
Delphi 7 Prof., PHP 5 (Eclipse 3 SDK)
BeitragVerfasst: Fr 09.05.03 10:42 
ich mach mal pseudo code:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
  i = länge vom string

  while i > 0 do
    begin
      erhöhe den ordinalwert von string[i] um eins.

      { wenn es vorher 9 (57) war, dann überlauf. wenn vorher Z (90) war,
        dann überlauf. wenn es vorher z (122) war, dann überlauf.
      
      wenn überlauf, dann
        Begin
           buchstabe string[i] wieder um eins verringern
           dec(i);
        End
          Else
       abbrechen, erfolgreich erhöht. (Break)
    end


so könnte es gehen. probier mal.



ase

_________________
-EN
discmix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Fr 09.05.03 13:16 
dann, ich probiere es mal...
Sieht so eigentlich ganz logisch aus :D
ase
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 203

Gentoo, Windows 9X, ME, 2k, NT, XP
Delphi 7 Prof., PHP 5 (Eclipse 3 SDK)
BeitragVerfasst: Fr 09.05.03 13:30 
freilich...

wenns net klappt oder du fragen hast muss halt nochmal jemand ran aber des sollte so gehn.


ase

[edit]
achso! du musst aufpassen wenn du dem ganzen ein zzzz übergibst! nur so als tip.

_________________
-EN
discmix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 13.05.03 21:13 
Ich habs mal so realisiert...

ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
function TForm1.Wert_erhoehen(Feld,Tabelle:String):String;
var Laenge,i,z : Integer;
    Next : Boolean;
    Vorn,Hinten,Wert:String;
begin
    z := 0;
    Next := false;
    Laenge:=Length(Wert);
    while Laenge > 0 do
    begin
        i:= ord(Wert[Laenge]);
        if i = 57 then i:= 65 else
        inc(i);
        next:=false;
        if i > 90 then
        begin
            i:=48;
            next := true;
        end;
        if next = true then
        begin
            vorn := copy(Wert,1,Laenge-1);
            hinten := copy(Wert,Laenge+1,length(wert));
            //insert(chr(i),Wert,Laenge);
            Wert:=vorn+chr(i)+hinten;
            dec(Laenge);
        end else
        begin
            vorn := copy(Wert,1,Laenge-1);
            hinten := copy(Wert,Laenge+1,length(wert));
            //insert(chr(i),Wert,Laenge);
            result:=vorn+chr(i)+hinten;
            break;
        end;
    end;
    if Laenge = 0 then result:='0'+Wert;
end;


Ist das logisch ? Oder kann man's noch rafinierter machen :shock: :oops:
ase
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 203

Gentoo, Windows 9X, ME, 2k, NT, XP
Delphi 7 Prof., PHP 5 (Eclipse 3 SDK)
BeitragVerfasst: Di 13.05.03 21:42 
servus

also des sieht ziemlich umständlich aus finde ich. bist du dir sicher das das was du da gepostet hast auch läuft?

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
function TForm1.Wert_erhoehen(Feld,Tabelle:String):String; 
var Laenge,i,z : Integer; 
    Next : Boolean; 
    Vorn,Hinten,Wert:String; 
begin 
    z := 0; 
    Next := false; 
    Laenge:=Length(Wert);


Frage: Wo nimmst du den Inhalt der Variablen 'Wert' her? du bestimmst zwar die Länge davon, aber hast doch der Variablen vorher nix zugewiesen :?:
Dann sind da noch so einige Sachen die ich da nich versteh aber ist jetzt nicht so wichtig.


so würde ich des machen:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
Procedure IncrementIndex(Var Index: String);
Var i: Integer;
    Done: Boolean;
Begin
  i := Length(Index);
  Repeat
    Done := True;
    Case Index[i] of
      #57: Index[i] := #65;
      #90: Index[i] := #97;
      #122: Begin
              Index[i] := #48;
              Dec(i);
              Done := False;
              If i = 0 then
                Begin
                  ShowMessage('bei zzzzzzzz angekommen.');
                  Exit;
                End;
            End;
         Else
           Index[i] := Chr(Ord(Index[i]) + 1);
    End;
  Until Done;
End; // getestet, funzt


Hab jetzt leider keine Zeit was zu kommentieren. wenn fragen sind, dann frag nochmal.


ase

_________________
-EN