AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Falls Variable(n) vorhanden mache das sonst mache dies
Thema durchsuchen
Ansicht
Themen-Optionen

Falls Variable(n) vorhanden mache das sonst mache dies

Ein Thema von thknub · begonnen am 26. Apr 2008 · letzter Beitrag vom 30. Apr 2008
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    
thknub

Registriert seit: 25. Apr 2008
12 Beiträge
 
Turbo Delphi für Win32
 
#1

Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 20:15
Hallo,

Ich möchte Programm zur Berechnung von Dreiecken coden. Dabei bin ich auf ein Problem gestoßen:

Ich möchte 6 Variablen, die man eingeben kann, aber nicht eingeben muss. Wenn ich z.B. nur 3 Variablen eingebe, soll das Programm trotzdem alles, was man damit errechnen kann, ausgeben.

Genau genommen würde das bedeuten:

Eingabe sind Variablen a,b,c,d,e,f

m := sin(d)*b/sin(e) oder wenn b oder e nicht vorhanden ist m := sin(d)*c/sin(f) und wenn keine nötige Variable vorhanen ist mache nichts

Ist das irgendwie zu bewerkstelligen?
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 20:18
Überprüfe doch den Inhalt der Variablen
Markus Kinzler
  Mit Zitat antworten Zitat
omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#3

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 20:23
Vielleicht hilft dir ja das weiter...

Delphi-Quellcode:
  TDreieck = class
  private
  public
    function Berechnung(a,b,c,d,e,f:integer):real; overload;
    function Berechnung(a,b,c,d,e:integer):real; overload;
    function Berechnung(a,b,c,d:integer):real; overload;
    function Berechnung(a,b,c:integer):real; overload;
    function Berechnung(a,b:integer):real; overload;
    function Berechnung():real; overload;
  end;
Gruss
Thorsten
  Mit Zitat antworten Zitat
Stefan92

Registriert seit: 9. Jan 2007
146 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 20:25
Falls es ohne die Variable zu einem Laufzeitfehler kommt, könntest du folgendes versuchen:

Delphi-Quellcode:
try
  m := sin(d)*b/sin(e);
except
  m := sin(d)*c/sin(f);
end;
Gruß

Stefan

Edit:
Vergiss meinen Vorschlag, es gibt bei deinem Problem zu viele Fälle.
@hoika: Ich glaube, thknub möchte wissen, wie man die Variablen auf leeren Inhalt prüft.
  Mit Zitat antworten Zitat
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.270 Beiträge
 
Delphi 10.4 Sydney
 
#5

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 20:26
Halloo,

6 Boolean-Variablen,
die anzeigen, ob die Variablen gefüllt worden sind.


Heiko
Heiko
  Mit Zitat antworten Zitat
Benutzerbild von inherited
inherited

Registriert seit: 19. Dez 2005
Ort: Rosdorf
2.022 Beiträge
 
Turbo Delphi für Win32
 
#6

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 20:27
oder du initalisierst sie einfach mit einem Wert der nicht eingegeben werden kann und überprüfst sie nachher darauf.
Nikolai Wyderka

SWIM SWIM HUNGRY!
Neuer Blog: hier!
  Mit Zitat antworten Zitat
thknub

Registriert seit: 25. Apr 2008
12 Beiträge
 
Turbo Delphi für Win32
 
#7

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 21:22
Wenn ich die Variante von omata benutze antwortet er mir [Pascal Fehler] E2065 Ungenügende Forward- oder External-Deklaration: 'TForm5.Berechnung'.

Hier nochmal der Code

Delphi-Quellcode:
unit Unit5;

interface

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

type
  TForm5 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Button1: TButton;
    Label13: TLabel;
    Label14: TLabel;
    Edit13: TEdit;
    Edit14: TEdit;
    Edit15: TEdit;
    Edit16: TEdit;
    Edit17: TEdit;
    Edit18: TEdit;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Edit19: TEdit;
    Edit20: TEdit;
    Edit21: TEdit;
    Edit22: TEdit;
    Label24: TLabel;
    Label25: TLabel;
    Edit23: TEdit;
    Edit24: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public

  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

procedure TForm5.Button1Click(Sender: TObject);




 var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r: REAL;

begin

a := StrToFloat(edit1.Text);
b := StrToFloat(edit2.Text);
c := StrToFloat(edit3.Text);
d := StrToFloat(edit4.Text);
e := StrToFloat(edit5.Text);
f := StrToFloat(edit6.Text);
g := sqrt(sqr(b)+sqr(c)-2*b*c*Cos(d));
h := sqrt(sqr(a)+sqr(c)-2*a*c*Cos(e));
i := sqrt(sqr(a)+sqr(b)-2*a*b*Cos(f));
j := ArcCos((sqr(b)+sqr(c)-sqr(a))/(2*b*c));
k := ArcCos((sqr(a)+sqr(c)-sqr(b))/(2*a*c));
l := ArcCos((sqr(a)+sqr(b)-sqr(c))/(2*a*b));
m := sin(d)*b/sin(e);
n := sin(e)*a/sin(d);
o := sin(f)*a/sin(d);
p := ArcSin((a*Sin(e))/b);
q := ArcSin((b*Sin(d))/a);
r := ArcSin((c*Sin(d))/a);

edit7.Text := FloatToStr(g);
edit8.text := FloatToStr(h);
edit9.Text := FloatToStr(i);
edit10.Text := FloatToStr(j);
edit11.Text := FloatToStr(k);
edit12.Text := FloatToStr(l);
edit13.Text := FloatToStr(m);
edit14.Text := FloatToStr(n);
edit15.text := FloatToStr(o);
edit16.Text := FloatToStr(p);
edit17.Text := FloatToStr(q);
edit18.Text := FloatToStr(r);


end;

end.
Wobei g und m sowie h und n das gleiche sind.(Hatte probiert es über verschiedene Ausgabefelder zu machen, aber es kommt immer folgende Nachricht, wenn ich auf testen klicke und nicht in alle Eingabe Felder etwas schreibe: " ist kein gültiger Gleitkommawert

Ich hätte auch nicht wirklich ein Problem damit 3 Ausgabefelder zu machen, wenn man wenigstens nicht überall was eingeben muss, wobei mir zwei oder auch nur eins besser gefielen...

@inherited
Ich versteh jetzt nicht so ganz, was du meinst
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#8

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 21:33
Zitat:
Wenn ich die Variante von omata benutze antwortet er mir [Pascal Fehler] E2065 Ungenügende Forward- oder External-Deklaration: 'TForm5.Berechnung'.
Du musst die Methoden natürlich auch implementieren.
Markus Kinzler
  Mit Zitat antworten Zitat
thknub

Registriert seit: 25. Apr 2008
12 Beiträge
 
Turbo Delphi für Win32
 
#9

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 26. Apr 2008, 22:13
Das mache ich wie? Kann mir mal jemand ein Bsp. geben? Sorry, ich bin noch ziemlich neu auf dem Gebiet (hab gestern Abend angefangen ein wenig rumzucoden)
  Mit Zitat antworten Zitat
hesubat

Registriert seit: 25. Dez 2005
Ort: Görlitz
19 Beiträge
 
Delphi 7 Personal
 
#10

Re: Falls Variable(n) vorhanden mache das sonst mache dies

  Alt 27. Apr 2008, 00:15
Was meinst Du zu folgender Loesung:

Code:
procedure TForm1.Button1Click(Sender: TObject);
var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r: REAL; bo1,bo2,bo3,bo4,bo5,bo6:boolean;
begin

bo1:=false; bo2:=false; bo3:=false; bo4:=false; bo5:=false; bo6:=false;
if edit1.text<>'' then begin a := StrToFloat(edit1.Text); bo1:=true; end;
if edit2.text<>'' then begin b := StrToFloat(edit2.Text); bo2:=true; end;
if edit3.text<>'' then begin c := StrToFloat(edit3.Text); bo3:=true; end;
if edit4.text<>'' then begin d := StrToFloat(edit4.Text); bo4:=true; end;
if edit5.text<>'' then begin e := StrToFloat(edit5.Text); bo5:=true; end;
if edit6.text<>'' then begin f := StrToFloat(edit6.Text); bo6:=true; end;
if bo2 and bo3 and bo4 then g := sqrt(sqr(b)+sqr(c)-2*b*c*Cos(d));
if bo1 and bo3 and bo5 then h := sqrt(sqr(a)+sqr(c)-2*a*c*Cos(e));
if bo1 and bo2 and bo6 then i := sqrt(sqr(a)+sqr(b)-2*a*b*Cos(f));
if bo1 and bo2 and bo3 then j := ArcCos((sqr(b)+sqr(c)-sqr(a))/(2*b*c));
if bo1 and bo2 and bo3 then k := ArcCos((sqr(a)+sqr(c)-sqr(b))/(2*a*c));
if bo1 and bo2 and bo3 then l := ArcCos((sqr(a)+sqr(b)-sqr(c))/(2*a*b));
if bo2 and bo4 and bo5 then m := sin(d)*b/sin(e);
if bo1 and bo4 and bo5 then n := sin(e)*a/sin(d);
if bo1 and bo4 and bo6 then o := sin(f)*a/sin(d);
if bo1 and bo2 and bo5 then p := ArcSin((a*Sin(e))/b);
if bo1 and bo2 and bo4 then q := ArcSin((b*Sin(d))/a);
if bo1 and bo3 and bo4 then r := ArcSin((c*Sin(d))/a);

edit7.Text := FloatToStr(g);
edit8.text := FloatToStr(h);
edit9.Text := FloatToStr(i);
edit10.Text := FloatToStr(j);
edit11.Text := FloatToStr(k);
edit12.Text := FloatToStr(l);
edit13.Text := FloatToStr(m);
edit14.Text := FloatToStr(n);
edit15.text := FloatToStr(o);
edit16.Text := FloatToStr(p);
edit17.Text := FloatToStr(q);
edit18.Text := FloatToStr(r);

end;
Heinz Subat
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:40 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