Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Währungsumrechner (https://www.delphipraxis.net/168547-waehrungsumrechner.html)

skatem 28. Mai 2012 13:27


Währungsumrechner
 
Sorry erstmal, ich wusste nicht, wo ichs sonst hätte reinschreiben sollen.
Naja ich habe mit Lazarus einen mehr oder weniger guten Währungsumrechner zu programmieren und wollte halt am Ende einen Button, mit dem ich alles umrechne, dann hab ichs so versucht, weil irgendwie hat das mit else nicht funktioniert, aber so macht der dann immer mehrer Rechnungen...
Delphi-Quellcode:
procedure TForm1.EurobuttonClick(Sender: TObject);
var rZahl, rOperand, rErgebnis: real;
begin
  if
  length(Euro.Text)>=1
  then
  rZahl:= StrToFloat ( Euro.Text);
  rOperand:= 1.25;
  rErgebnis:= rZahl*rOperand;
  Dollar.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Euro.Text);
  rOperand:= 0.79;
  rErgebnis:= rZahl*rOperand;
  Pfund.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Euro.Text);
  rOperand:= 40.18;
  rErgebnis:= rZahl*rOperand;
  Rubel.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Euro.Text);
  rOperand:= 99.76;
  rErgebnis:= rZahl*rOperand;
  Yen.Text:= FloatToStr ( rErgebnis);

  if

  length(Dollar.Text)>=1

  then

   rZahl:= StrToFloat ( Dollar.Text) ;
  rOperand:= 0.79;
  rErgebnis:= rZahl*rOperand ;
  Euro.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Dollar.Text) ;
  rOperand:= 0.63;
  rErgebnis:= rZahl*rOperand ;
  Pfund.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat (Dollar.Text) ;
  rOperand:= 32.07;
  rErgebnis:= rZahl*rOperand ;
  Rubel.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Dollar.Text) ;
  rOperand:= 79.63;
  rErgebnis:= rZahl*rOperand ;
  Yen.Text:= FloatToStr ( rErgebnis);



  if length(Pfund.Text)>=1

  then
  rZahl:= StrToFloat ( Pfund.Text) ;
  rOperand:= 1.25;
  rErgebnis:= rZahl*rOperand ;
  Euro.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Pfund.Text) ;
  rOperand:= 1.56;
  rErgebnis:= rZahl*rOperand ;
  Dollar.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat (Pfund.Text) ;
  rOperand:= 50.23;
  rErgebnis:= rZahl*rOperand ;
  Rubel.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Pfund.Text) ;
  rOperand:= 124.73;
  rErgebnis:= rZahl*rOperand ;
  Yen.Text:= FloatToStr ( rErgebnis);

  if length(Rubel.Text)>=1
  then
  rZahl:= StrToFloat ( Rubel.Text) ;
  rOperand:= 0.02;
  rErgebnis:= rZahl*rOperand ;
  Euro.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Rubel.Text) ;
  rOperand:= 0.03;
  rErgebnis:= rZahl*rOperand ;
  Dollar.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat (Rubel.Text) ;
  rOperand:= 0.01;
  rErgebnis:= rZahl*rOperand ;
  Pfund.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Rubel.Text) ;
  rOperand:= 2.48;
  rErgebnis:= rZahl*rOperand ;
  Yen.Text:= FloatToStr ( rErgebnis);


  if length(Yen.Text)>=1

  then
  rZahl:= StrToFloat ( Yen.Text) ;
  rOperand:= 0.010;
  rErgebnis:= rZahl*rOperand ;
  Euro.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Yen.Text) ;
  rOperand:= 0.012;
  rErgebnis:= rZahl*rOperand ;
  Dollar.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Yen.Text) ;
  rOperand:= 0.008;
  rErgebnis:= rZahl*rOperand ;
  Pfund.Text:= FloatToStr ( rErgebnis);

  rZahl:= StrToFloat ( Yen.Text) ;
  rOperand:= 0.402;
  rErgebnis:= rZahl*rOperand ;
  Rubel.Text:= FloatToStr ( rErgebnis);

   end;
Danke schonmal im vorraus

implementation 28. Mai 2012 13:33

AW: Währungsumrechner
 
Versuch mal, den Code, der jeweils zu einer Bedingung gehört, in
Delphi-Quellcode:
begin ... end;
zu setzen. Dann dürft's funktionieren ;)

himitsu 28. Mai 2012 13:34

AW: Währungsumrechner
 
Delphi-Quellcode:
if ... then
  // ein Befehl


if ... then
begin
  // mehrere Befehle
end;
Tipp: Das nächste Mal selber debuggen und scon siehst du warum etwas nicht geht.
Jedenfalls dieser Fehler wäre sofort aufgefallen.

Und nochwas:
Debuggen solltest du dennoch, damit du das nächste Problem erkennst.
Tipp: ELSE


noch'n Tipp:
Delphi-Quellcode:
if length(Euro.Text)>=1 then
entspricht
Delphi-Quellcode:
if Euro.Text <> '' then



Und es wäre schön, wenn du das [delphi]-Tag noch reinmachen könntest.

Die grauenhafte Codeformatierug erwähnen wir besser mal nicht. :roll:

skatem 28. Mai 2012 13:38

AW: Währungsumrechner
 
ok, danke schonmal, ich probier es mal aus

skatem 28. Mai 2012 13:51

AW: Währungsumrechner
 
irgendwie versteh ich das Problem nicht genau, weil immer wenn ich ein else einsetzte steht da: Unit1.pas(159,1) Fatal: Syntax error, ";" expected but "ELSE" found.
und wenn ich das weg lasse rechnet der die einzelnen schritte alle nacheinander durch, glaube ich, weil wenn ich dann bei Euro 1 eingebe steht bei Euro am ende ne 0 mit 6 Nachkommastellen.

himitsu 28. Mai 2012 13:58

AW: Währungsumrechner
 
Nicht glauben sondern nachsehn! (debuggen)

Bei Google suchendelphi tutorial else

skatem 28. Mai 2012 14:10

AW: Währungsumrechner
 
ok das Problem ist gelöst:-D
Danke

Impulz 29. Mai 2012 06:28

AW: Währungsumrechner
 
Am besten wäre es, wenn man sich wenigstens das Basiswissen aneignet...


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz