Autor Beitrag
chriss1988
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 09:35 
wie kann ich es am geschktesten machen, das er mir eine fehlereldung bring, wen ich x / 0 teilen will


und meune 2 frage wen ich hir einen quelltext reinkopier wie mach ich es das es so aussieht wie bei den anderen

meiner sieht so aus
ausblenden volle Höhe Delphi-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:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    private
      { Private-Deklarationen }
    public
      { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  zahl1, zahl2, ergebnis: real ;
  operator: string;
  begin
  operator:=Edit3.Text ;
  zahl1:=strTofloat(Edit1.Text);
  zahl2:=StrTofloat(Edit2.Text);

  if operator = '+' then
    ergebnis := Zahl1 + Zahl2;
  if operator = '-' then
    ergebnis :=  Zahl1 - Zahl2;
  if operator = '*' then
    ergebnis :=  Zahl1 * Zahl2;
  if operator = '/' then
    ergebnis :=  Zahl1 / Zahl2;
   if zahl2 = '0' then
   ergebniss := 'error'
 // das klappt aber net
    
  edit4.text := floattostr  (ergebnis);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close ;
end;

end.



achja das is das programm wo eine fehlermeldung auftreten soll

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt.
Moderiert von user profile iconKlabautermann: Topic aus Sonstiges verschoben am Di 27.09.2005 um 15:12
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 09:39 
Ich würde sagen du prüfst Zahl zwei bevor du / rechnest.
Wenn du das erst danach prüfst, dann wirft dich eine Exception raus,
invalidfloatingpointoperation oder so.

Mach die Prüfung vor dem / Rechnen das müsste dann schon funktionieren.

Ausserdem, kannst du einer Real Variable (Ergebnis) keinen String zuweisen.

Gruß Sunspeed,

hoffe geholfen zu haben
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 09:42 
und wie davor
du meinst das ich die if anweisung nach oben setzen soll
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Di 27.09.05 09:44 
ausblenden Delphi-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:
procedure TForm1.Button1Click(Sender: TObject);
var
  zahl1, 
  zahl2, 
  ergebnis: real ;
  operator: Char;
  Error: String;
begin
  operator:=Edit3.Text[1] ;
  zahl1 := StrTofloat(Edit1.Text);
  zahl2 := StrTofloat(Edit2.Text);
  Error := '';
  //EDIT
  Ergebnis := 0;
case operator of
  '+': Ergebnis := Zahl1 + Zahl2;
  '-': Ergebnis := Zahl1 - Zahl2;
  '*': Ergebnis := Zahl1 * Zahl2;
  '/': begin
         if Zahl2<>0 then Ergebnis := Zahl1 / Zahl2
                     else Error := 'Division durch Null';
       end;
  //EDIT
  else Error := 'Keine Operation eingegeben';
end;
  Label1.Caption := FloatToStr (ergebnis);
  Label2.Caption := Error;
end;


Zuletzt bearbeitet von Kroko am Di 27.09.05 09:54, insgesamt 2-mal bearbeitet
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 09:48 
Ja genau, ungefähr so




ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if operator = '/' then
begin
 if zahl2 <> '0' then
  ergebnis := Zahl1 / Zahl2
 else
  edit4.text := 'error das klappt aber net'
end;


so denk ich müsste das funktionieren.

Gruß Sunspeed

_________________
Tiefe Brunnen muss man graben, wenn man klares Wasser will.
Tiefe Wasser sind nicht still!
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 09:52 
Das Problem bei der ertsen Variante besteht noch darin,
was passiert wenn sich ein lustiger Benutzer des Programms
einen scherz erlaubt und ein Leerzeichen eingibt und dann erst
den Operator?

ausblenden Delphi-Quelltext
1:
 operator:=Edit3.Text;					


mach ein Trim davor, und mach aus Operator ein char, das müsste reichen.

Sunspeed

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 09:55 
das funktioniert net
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 09:56 
was funktioniert net?
bisschen genauer brauchen wir es schon. :wink: :?:
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 10:13 
ausblenden volle Höhe Delphi-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:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);

    private
      { Private-Deklarationen }
    public
      { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  zahl1, zahl2, ergebnis: real ;
  operator: string;
  begin
  operator:=Edit3.Text ;
  zahl1:=strTofloat(Edit1.Text);
  zahl2:=StrTofloat(Edit2.Text);

  if operator = '+' then
    ergebnis := Zahl1 + Zahl2;
  if operator = '-' then
    ergebnis :=  Zahl1 - Zahl2;
  if operator = '*' then
    ergebnis :=  Zahl1 * Zahl2;
  if operator = '/' then
  ergebnis := zahl1 / zahl2;
  end;
begin
 [b]if zahl2 <> 0 then[/b] da zeigt er mir en fehler an [Fehler] Unit1.pas(54): Undefinierter Bezeichner: 'zahl2'
  
ergebnis := Zahl1 / Zahl2
 else
  edit4.text := 'error das klappt aber net'
end;


  edit4.text := floattostr  (ergebnis);
end;

end.


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Di 27.09.05 10:19 
ausblenden volle Höhe Delphi-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:
unit Unit1;


procedure TForm1.Button1Click(Sender: TObject);
var
  zahl1, zahl2, ergebnis: real ;
  operator: string;
  begin
  operator:=Edit3.Text ;
  zahl1:=strTofloat(Edit1.Text);
  zahl2:=StrTofloat(Edit2.Text);

  if operator = '+' then
    ergebnis := Zahl1 + Zahl2;
  if operator = '-' then
    ergebnis :=  Zahl1 - Zahl2;
  if operator = '*' then
    ergebnis :=  Zahl1 * Zahl2;
  if operator = '/' then
  ergebnis := zahl1 / zahl2;
  end;  // ENDE der Prozedur !!!!
begin
 [b]if zahl2 <> 0 then[/b] da zeigt er mir en fehler an [Fehler] Unit1.pas(54): Undefinierter Bezeichner: 'zahl2'
  
ergebnis := Zahl1 / Zahl2
 else
  edit4.text := 'error das klappt aber net'
end;


  edit4.text := floattostr  (ergebnis);
end;

end.


Klar?

_________________
We are, we were and will not be.
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 10:21 
und nun fehler bei else

[Fehler] Unit1.pas(61): ';' nicht erlaubt vor einem 'ELSE'
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 10:21 
Sorry, aber wie lange programmierst du schon?
Glaubst du dass der Quellcode wenn du ihn durchliest funktioniert?
Es ist klar dass er nicht funktioniert.

ausblenden volle Höhe Delphi-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:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    Edit3: TEdit;
    Edit4: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    private
      { Private-Deklarationen }
    public
      { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  zahl1, zahl2, ergebnis: real ;
  operator: char;
  tmpstring:string;
  error:string;
begin
  tmpstring:=trim(Edit3.Text);
  operator:=tmpstring[1];
  error:='';

  try
   zahl1:=strTofloat(Edit1.Text);
   zahl2:=StrTofloat(Edit2.Text);
  except
   error:='Es wurde keine Zahl eingegeben';
   exit;
  end;

  if operator = '+' then
    ergebnis := Zahl1 + Zahl2;
  if operator = '-' then
    ergebnis :=  Zahl1 - Zahl2;
  if operator = '*' then
    ergebnis :=  Zahl1 * Zahl2;

  if operator = '/' then
  begin
   if zahl2 <> 0 then
    ergebnis :=  Zahl1 / Zahl2
   else
    error:='Division durch Null';
  end;
    
  edit4.text := floattostr(ergebnis);
  label2.caption:=error;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
close ;
end;

end

_________________
Tiefe Brunnen muss man graben, wenn man klares Wasser will.
Tiefe Wasser sind nicht still!
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 10:26 
1 monat und sorry das ich euch generft hab
dan geh ich halt in en anderes forum
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 10:31 
Du hast nicht genervt, aber es wird immer wieder erwartet, dass in den Foren der
gesamte Quellcode geschrieben wird und dann verwendet wird.

Meiner Meinung nach sollte das Forum eine Hilfe nebenbei sein um Fragen zu beantworten und nicht um Quellcode für andere (betrifft nicht nur mich) zu schreiben.

Es ist wichtig dass fragen konkret gestellt werden.

Ein sprichwort sagt, wie du es in den Wald hinein schreist, so kommt es zu dir zurück.

Ausserdem wie soll jemand Erfahrung Sammeln bzw. das Programmieren lernen wenn
der quellcode immer von anderen korrigiert oder gar geschrieben wird?
Try and Error, so lernt man selbst am schnellsten, gerade wenn man erst 1 Monat programmiert.
Fragen wie: "warum kommt der Fehler ; vor else nicht erlaubt" sind völlig in Ordnung,
du wirst eine Antwort in der Form bekommen, dass das Syntaktisch nicht erlaubt ist in
Delphi.

Ich hoffe dass ich jetzt nciht mit diesem Kommentar gegen dass DelphiForum Gesetzbuch verstoße. Aber sowas muss gesagt werden.

Ausserdem glaube ich mich recht zu erinnern, dass in den Nutzungsbedingungen dasselbe drin steht.

Also, wir/ich helfe dir gerne, aber bitte konkrete Fragen nicht sowas wie

"Funktioniert aber net",
oder "jetzt auch ncoh Fehler ';' for else" oder so.

Sorry.

Hoffe trotzdem geholfen zu haben.

Gruß sunspeed

_________________
Tiefe Brunnen muss man graben, wenn man klares Wasser will.
Tiefe Wasser sind nicht still!


Zuletzt bearbeitet von sunspeed am Di 27.09.05 10:37, insgesamt 1-mal bearbeitet
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 10:37 
ok sorry
aber ich kenn mich noch net so gut aus und wen dan noch begriffe fllen die ich noch nie gehört hab is das auch nicht gut.

ok das nächste mal stell ich die fragen genauer und beende das programm

kennst du oder andere noch en paar anfänger programme

mfg
chriss
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 10:41 
Anfänger Programme, huh, du fragst sachen ;-)

Versuch das Programm (den Rechner) doch trotzdem zu schreiben.
Wie gesagt, konkrete Fragen bei Fehlern und du wirst eine
Hilfreiche Antwort bekommen.

Der ; vor dem else ist syntaktisch (Gramatik in Delphi) nicht erlaubt.

Ich hab dir den code vorher noch komplett gepostet, verwende Ihn und analysiere Ihn mit dem alten von dir, schau wo die Änderungen sind und frage warum und wo die änderungen gemacht wurden / werden mussten.

Gruß Sunspeed

_________________
Tiefe Brunnen muss man graben, wenn man klares Wasser will.
Tiefe Wasser sind nicht still!
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 10:54 
danke

das programm is schon fertig wollte nur als zusatz noch das mit dem error befehl einbaun aber das is doch noch etwas zu hoch für mich

danke aber trotzdem
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 11:05 
Also ich programmiere jetzt seit 5 Jahren,
ich hab mir das Programmieren mehr oder weniger selbst gelernt.
Am Anfang hatte ich das Problem, woher soll ich die Informationen
bzw. die Grundsätze erlernen?
Dein Schritt ins Forum war schon nicht schlecht.

Welches Delphi verwendest du?

Ich kann dir das Buch Borland Delphi 7 Grundlagen und Profiwissen von Hanser
empfehlen, darin stehen alle Grundlegenden Dinge und es sind auch
Programme drin für Anfänger, da kannst du dir einen Wolf programmieren!

Aber wie gesagt, recherchiere (hoffe das schreibt man so;-)) erst mal, woher
du die Informationen bekommst.
Ich kann dir auch die Tutorials von DsDt empfehlen (www.delphi-source.de).

Also, ich wünsch dir viel erfolg für deinen weiteren Programmiererwerdegang.

mfg
Sunspeed

P.S.: Scheue dich nicht Fragen zu stellen! Aber du weißt ja, konkret ;-)

_________________
Tiefe Brunnen muss man graben, wenn man klares Wasser will.
Tiefe Wasser sind nicht still!
chriss1988 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Di 27.09.05 11:09 
hab delphi 5 das haben wir auch in der schule
sunspeed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 99

Win 95, Win 98,WinME,W2k Win XP
Delphi 4 Pers,Delphi 7 Prof, Delphi 2005 Arch, VS 2003, VS 2005, C#
BeitragVerfasst: Di 27.09.05 11:22 
Gut wenn dus in der Schule eh lernst, dann "sollten" normalerweise
mit der Zeit die ganzen Grundlegenden Dinge sowieso dran kommen.

Also fleißig aufpassen! ;-)

gruß sunspeed

_________________
Tiefe Brunnen muss man graben, wenn man klares Wasser will.
Tiefe Wasser sind nicht still!