Autor Beitrag
Quivadis
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314

UBUNTU 9.04
D2005 PERS, JAVA, D7 Pers.
BeitragVerfasst: Fr 01.04.05 15:14 
Hallo Freunde,

habe ein kleines Problem. Ich möchte in einer Inputbox nur floatzahlen zulassen. Deren Bereich habe ich schon beschränkt.

Wie bekomme ich es aber auch noch hin das nur zahlen und komma erlaubt ist?

Hier mein jetziger code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
begin
  try
    repeat
      lmasstab_cm:=StrToFloat(InputBox('Eingabedialog','Eingabe der wahren Länge in cm:','5'));
    until ((Lmasstab_cm>=0and (Lmasstab_cm<=999999));

  except;
  end;
end;



Quivadis

_________________
Wissen ist macht, nichts wissen macht auch nichts. ODER: Wer nichts weis, kann nichts vergessen.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 15:26 
Mach doch einfach sowas da:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure Blublabb;
var
Text: String;
Zahl: Real;
begin
Text := InputBox('Eingabedialog','Eingabe der wahren Länge in cm:','5');
try
Zahl := StrToFloat(Text);
except
ShowMessage('Keine Zahl.');
end;
end;

Wenn du eine Exception im try-except-end;-Block bekommst, dann weißt du, dass es keine Float ist, weil er's nicht umwandeln kann. ;)

Alternativ könntest du eine Schleife bauen und damit alle Zeichen durchfragen und schauen ob's alles eins von "0123456789," ist. ;)
Quivadis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314

UBUNTU 9.04
D2005 PERS, JAVA, D7 Pers.
BeitragVerfasst: Fr 01.04.05 16:08 
WeBsPaCe, danke für deine Hilfe. Funktioniert aber noch nicht so wie ich es mir denke.

Die Inputbox muss aber solange bleiben bis die Eingabe korrekt ist. Das ist das eigentliche Problem. Der Anwender muss etwas eingaben und diese Eingabe muss richtig sein.

_________________
Wissen ist macht, nichts wissen macht auch nichts. ODER: Wer nichts weis, kann nichts vergessen.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 16:10 
Was ist mit ner Schleife?? :gruebel:
Quivadis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314

UBUNTU 9.04
D2005 PERS, JAVA, D7 Pers.
BeitragVerfasst: Fr 01.04.05 16:18 
wenn schleife dann nur repeat until möglich, weiss ja nicht wieviele Versuche der Anwender braucht, bis er es richtig hinbekommen hat.

Das ist Problem. Ich kann leider auch kein neues Formular draus machen, weil ganzes Projekt soll mal eine eigne Komponennte werden.

Ich brauche also eine Lösung die irgendwie unsere beide Lösungen in eine packt, würde ich denken.

_________________
Wissen ist macht, nichts wissen macht auch nichts. ODER: Wer nichts weis, kann nichts vergessen.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 16:23 
Mensch Junge!! Denk doch mal nach!! ;) Ist doch nicht so schwer. (Vorausgesetzt, ich hab dich richtig verstanden... :mrgreen: )

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
var
Text: String;
Fehler: Boolean;
begin
Text := '5';
repeat
Fehler := False;
Text := InputBox('Eingabedialog','Eingabe der wahren Länge in cm:',Text);
try
if (StrToFloat(Text) < 0or (StrToFloat(Text) > 999999then Fehler := True;
except
Fehler := True;
end;
until not Fehler;
end;
HolgerB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 91

Win XP
D6 Pers
BeitragVerfasst: Fr 01.04.05 16:24 
Hallo,

ich würde im Ereignis onExit überprüfen, ob es sich um eine Floatzahl handelt. Wenn nicht, kannst du über Showmessage eine Nachricht anzeigen und den Handle wieder auf das Editfeld setzen, bis die Eingabe passt.

Gruß
Holger

Edit: Sory, ich war bei einem Editfeld. Vergesst es einfach... :oops:
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 16:27 
Er kann doch kein selbstständiges Formular nehmen. Muss doch InputBox verwenden. ;)
Quivadis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 314

UBUNTU 9.04
D2005 PERS, JAVA, D7 Pers.
BeitragVerfasst: Fr 01.04.05 16:30 
Habe es getestet und es scheint zu funktionieren.

Danke dir @WeBsPaCe

Hätte ich aber eigentlich auch von alleine drauf kommen können, aber man ist halt doch etwas ... :autsch: :autsch: :autsch: :autsch: hoffe das hilft :lol: :lol: :lol:

_________________
Wissen ist macht, nichts wissen macht auch nichts. ODER: Wer nichts weis, kann nichts vergessen.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Fr 01.04.05 16:32 
kP... :lol:

Dafür ist das DF doch da!! ;) War ja nicht böse gemeint.. ;)