Delphi-PRAXiS
Seite 3 von 4     123 4      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Wie kann ich das rechnen (https://www.delphipraxis.net/74405-wie-kann-ich-das-rechnen.html)

_frank_ 19. Aug 2006 12:14

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
if rb_4rings.Checked then
begin
  case cb_ring4.ItemIndex of
    0:prozent:=10;
    1:prozent:=5;
    2:prozent:=1;
    3:prozent:=2;
    4:prozent:=0.5;
    5:prozent:=0.25;
    6:prozent:=0.1;
  end;
  pnl_Tolerance.Caption:= format('%.2f',[prozent]);
end;
Zitat:

Zitat von _frank_
Delphi-Quellcode:
pnl_worstcasemin.caption := floattostr(widerstand-tolerance)+' Ohm';

Gruß Frank

Gehstock 19. Aug 2006 12:20

Re: Wie kann ich das rechnen
 
Liste der Anhänge anzeigen (Anzahl: 1)
Bokomme aber fehler bei
Delphi-Quellcode:
pnl_worstcasemin.caption := floattostr(widerstand-tolerance)+' Ohm';
pnl_worstcasemax.caption := floattostr(widerstand+tolerance)+' Ohm';

invalid floating point operation

Hawkeye219 19. Aug 2006 12:23

Re: Wie kann ich das rechnen
 
Du solltest den Wert für tolerance berechnen, bevor du ihn verwendest:

Delphi-Quellcode:
if (widerstand)<1000 then begin
pnl_result.caption := (floattostr((widerstand)/1))+' Ohm';
pnl_worstcasemin.caption := (floattostr((widerstand)/1-(tolerance)))+' Ohm'; // <<-- verwendet
pnl_worstcasemax.caption := (floattostr((widerstand)/1+(tolerance)))+' Ohm'; // <<-- verwendet
end;
tolerance := (widerstand)/100*(prozent); // <<----- zu spät berechnet!
Gruß Hawkeye

Gehstock 19. Aug 2006 12:32

Re: Wie kann ich das rechnen
 
Nee das ist es nicht selbes ergebnis

Delphi-Quellcode:
if rb_4rings.Checked then
begin
  case cb_ring4.ItemIndex of
    0:prozent:=10;
    1:prozent:=5;
    2:prozent:=1;
    3:prozent:=2;
    4:prozent:=0.5;
    5:prozent:=0.25;
    6:prozent:=0.1;
  end;
  pnl_Tolerance.Caption:= format('%.2f',[prozent])+' %';
end;
und wi bekomme ich an der stelle hin das er nicht 10,00 % anzeigt sondern nur 10 %

Klaus01 19. Aug 2006 12:38

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
pnl_Tolerance.Caption:= format('%g',[prozent])+' %';
Versuche es einmal damit, ein Blick in die Hilfe würde auch nicht schaden.

Grüße
Klaus

Jürgen Thomas 19. Aug 2006 12:44

Re: Wie kann ich das rechnen
 
Zitat:

Zitat von Gehstock
und wi bekomme ich an der stelle hin das er nicht 10,00 % anzeigt sondern nur 10 %

Delphi-Referenz durchsuchenFormat-Strings
Delphi-Quellcode:
pnl_Tolerance.Caption:= format('%f %%',[prozent]);
Jürgen

_frank_ 19. Aug 2006 12:52

Re: Wie kann ich das rechnen
 
Zitat:

Zitat von Gehstock
Nee das ist es nicht selbes ergebnis

das war auch nur der untere Teil als Anhaltspunkt...
ich denke, *DU* willst programmieren...

Gruß Frank

Gehstock 19. Aug 2006 13:00

Re: Wie kann ich das rechnen
 
ganz ohne Tolerance hab ich doch auch schon versucht

Delphi-Quellcode:
pnl_worstcasemin.caption := (floattostr((widerstand)/1-(widerstand)/100*(prozent)))+' Ohm';
pnl_worstcasemax.caption := (floattostr((widerstand)/1+(widerstand)/100*(prozent)))+' Ohm';
Ergebnis bleibt das selbe

Klaus01 19. Aug 2006 13:14

Re: Wie kann ich das rechnen
 
ein Hoch auf die Mathematik und die Möglichkeit Formeln umzustellen:

Delphi-Quellcode:
pnl_worstcasemin.caption := floattostr(widerstand*(1-prozent/100))+' Ohm';
pnl_worstcasemin.caption := floattostr(widerstand*(1+prozent/100))+' Ohm';
Grüße
Klaus

_frank_ 19. Aug 2006 13:14

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var widerstand,tolerance:extended;
const prozent=2.5;
begin
  widerstand:=StrToFloat(Edit1.text);
  tolerance:=widerstand/100*prozent;
  edit2.text:=FloatToStr(Tolerance);
  edit3.text:=floattostr(widerstand-tolerance)+' Ohm';
  edit4.text:=floattostr(widerstand+tolerance)+' Ohm';
end;
also bei mir haut das hin...du musst ggf. prüfen, ob deine Berechnungen vorher i.O. sind

//edit: warum denn die 1?

Gruß Frank


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:29 Uhr.
Seite 3 von 4     123 4      

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