Delphi-PRAXiS
Seite 2 von 4     12 34      

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)

Martin K 3. Aug 2006 22:25

Re: Wie kann ich das rechnen
 
Zitat:

Zitat von Gehstock
Delphi-Quellcode:
tolerance := floattostr((strtofloat((pnl_result.caption)/100)*prozent));

Wenn du mir verrätst, von welchem Typ tolerance ist, dann verrat ich dir auch, ob FloatToStr an dieser Stelle funktioniert oder nicht.
Selbes gilt für prozent.

Des Weiteren wäre es auch nicht verkehrt uns mitzuteilen, welche Fehlermeldungen kommen.

Klaus01 4. Aug 2006 07:56

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
tolerance := floattostr( (strtofloat(pnl_result.caption)/100)*prozent);
Sollte gehen wenn Prozent ein Integer- oder Floatwert ist und tolerance ein String ist.

Grüße
Klaus

Gehstock 19. Aug 2006 10:27

Re: Wie kann ich das rechnen
 
ich werds nie raffen

Delphi-Quellcode:
widerstand : string;
tolerance: extended;
prozent: extended;
Delphi-Quellcode:
tolerance := floattostr( (strtofloat(widerstand)/100)*(prozent));
und hier die Formel mit dem Problem

Delphi-Quellcode:
pnl_worstcasemin.caption := (floattostr((strtofloat(widerstand)/
1-(tolerance))+' Ohm'));
die klappt einwandfrei

Delphi-Quellcode:
pnl_result.caption := (floattostr((strtofloat(widerstand)/
1))+' Ohm');

_frank_ 19. Aug 2006 10:48

Re: Wie kann ich das rechnen
 
wenn ich das richrig sehe, hast du die klammern falsch gesetzt...

Delphi-Quellcode:
//aus
pnl_worstcasemin.caption := (floattostr((strtofloat(widerstand)/1-(tolerance))+' Ohm'[color=#ff0000])[/color]);
//wird
pnl_worstcasemin.caption := (floattostr((strtofloat(widerstand)/1-(tolerance))[color=#00ff00])[/color]+' Ohm');
//achja, division durch 1 und die stringroutinen...
var widerstand:extended;
pnl_worstcasemin.caption := floattostr(widerstand-tolerance)+' Ohm';
lässt sich doch viel leichter lesen, oder? :o

//edit
@mkinzler (nachfolgendes post): hab mich schon gewundert...wegen dem /(1-tolerance), er hat die prozentuale toleranz schon.
warum hast du das farbige komplett raus? hätte Eindruck gemacht.

Gruß Frank

mkinzler 19. Aug 2006 10:52

Re: Wie kann ich das rechnen
 
Du scheinst uns nicht zu trauen, da du unsere Ratschläge mit einer Bestimmtheit igonierst.
Man rechnet nicht mit strings.
Delphi-Quellcode:
widerstand : Extended;
Delphi-Quellcode:
tolerance := widerstand/100*prozent;
Delphi-Quellcode:
pnl_worstcasemin.caption := floattostr(widerstand-tolerance)+' Ohm';
Delphi-Quellcode:
pnl_result.caption := floattostr(widerstand)+' Ohm';

Gehstock 19. Aug 2006 11:13

Re: Wie kann ich das rechnen
 
Dsa klappt so net immer wenn ich irgendwas verändere klappt was anderes wieder nicht

deswegen mal komplett nich meckern binn noch nicht fertig mit dem optimieren der Normwiderstände

Delphi-Quellcode:
procedure TForm2.btn_executeClick(Sender: TObject);
var
wert : string;
widerstand : string;
tolerance: string;
prozent: extended;

begin
if rb_4rings.Checked then begin                     ++++++wollte ich umstellen (case) tut dann aber auch dumm
wert := floattostr(((cb_ring1.ItemIndex+1)*10) + cb_ring2.ItemIndex);
if cb_ring3.ItemIndex = 0 then widerstand := floattostr((strtofloat(wert)/100));
if cb_ring3.ItemIndex = 1 then widerstand := floattostr((strtofloat(wert)/10));
if cb_ring3.ItemIndex = 2 then widerstand := floattostr((strtofloat(wert)*1));
if cb_ring3.ItemIndex = 3 then widerstand := floattostr((strtofloat(wert)*10));
if cb_ring3.ItemIndex = 4 then widerstand := floattostr((strtofloat(wert)*100));
if cb_ring3.ItemIndex = 5 then widerstand := floattostr((strtofloat(wert)*1000));
if cb_ring3.ItemIndex = 6 then widerstand := floattostr((strtofloat(wert)*10000));
if cb_ring3.ItemIndex = 7 then widerstand := floattostr((strtofloat(wert)*100000));
if cb_ring3.ItemIndex = 8 then widerstand := floattostr((strtofloat(wert)*1000000));
if cb_ring3.ItemIndex = 9 then widerstand := floattostr((strtofloat(wert)*10000000));
end;

if rb_5rings.Checked then begin
wert := floattostr(((cb_ring1.ItemIndex+1)*100) + ((cb_ring2.ItemIndex)*10) + (cb_ring53.ItemIndex));
if cb_ring54.ItemIndex = 0 then widerstand := floattostr((strtofloat(wert)/100));
if cb_ring54.ItemIndex = 1 then widerstand := floattostr((strtofloat(wert)/10));
if cb_ring54.ItemIndex = 2 then widerstand := floattostr((strtofloat(wert)*1));
if cb_ring54.ItemIndex = 3 then widerstand := floattostr((strtofloat(wert)*10));
if cb_ring54.ItemIndex = 4 then widerstand := floattostr((strtofloat(wert)*100));
if cb_ring54.ItemIndex = 5 then widerstand := floattostr((strtofloat(wert)*1000));
if cb_ring54.ItemIndex = 6 then widerstand := floattostr((strtofloat(wert)*10000));
if cb_ring54.ItemIndex = 7 then widerstand := floattostr((strtofloat(wert)*100000));
if cb_ring54.ItemIndex = 8 then widerstand := floattostr((strtofloat(wert)*1000000));
if cb_ring54.ItemIndex = 9 then widerstand := floattostr((strtofloat(wert)*10000000));
end;
begin
if StrTofloat(widerstand)>=1000000 then begin
pnl_result.caption := (floattostr((strtofloat(widerstand)/
1000000))+' MOhm');
pnl_worstcasemin.caption := '?';
pnl_worstcasemax.caption := '?';
end;
if StrTofloat(widerstand)>=1000  then begin
if  StrTofloat(widerstand)<1000000  then begin
pnl_result.caption := (floattostr((strtofloat(widerstand)/
1000))+' KOhm');
pnl_worstcasemin.caption := '?';
pnl_worstcasemax.caption := '?';
end;
end;
if StrTofloat(widerstand)<1000 then begin
pnl_result.caption := (floattostr((strtofloat(widerstand)/                ++++++das klappt
1))+' Ohm');
pnl_worstcasemin.caption := (floattostr((strtofloat(widerstand)/          ++++++und hier das problem
1+(tolerance))+' Ohm'));
pnl_worstcasemax.caption := (floattostr((strtofloat(widerstand)/          ++++++und hier das problem
1+(tolerance))+' Ohm'));
end;
tolerance := floattostr( (strtofloat(widerstand)/100)*(prozent));
if rb_5rings.Checked then begin

if cb_ring55.ItemIndex = 0 then begin                 ++++++wollte ich umstellen (case) tut dann aber auch dumm
pnl_Tolerance.Caption:= '5%';
prozent:=(5);
end;
if cb_ring55.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=(1);
end;
if cb_ring55.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=(2);
end;
if cb_ring55.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=(0.5);
end;
if cb_ring55.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=(0.25);
end;
if cb_ring55.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=(0.1);
end;
end;

if rb_4rings.Checked then begin

if cb_ring4.ItemIndex = 0 then begin
pnl_Tolerance.Caption:= '10%';
prozent:=(10);
end;
if cb_ring4.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '5%';
prozent:=(5);
end;
if cb_ring4.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=(1);
end;
if cb_ring4.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=(2);
end;
if cb_ring4.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=(0.5);
end;
if cb_ring4.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=(0.25);
end;
if cb_ring4.ItemIndex = 6 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=(0.1);
end;
end;

end;
end;



procedure TForm2.btn_execute_preresistClick(Sender: TObject);

begin                                                  +++hier bin ich noch nicht fertig mit umbauen
case trunc(resistor) of                                +++seit ich das so hab bleibt das panel beim ersten
 25000..33001:pnl_normresistor.Caption := '27 KOhm';   +++drücken des Buttons leer erst beim 2. betätigen
 16500..22001:pnl_normresistor.Caption := '22 KOhm';   +++erfolgt die ausgabe
 13500..16499:pnl_normresistor.Caption := '18 KOhm';
 12000..13499:pnl_normresistor.Caption := '15 KOhm';
10000..11999:pnl_normresistor.Caption := '12 KOhm';
8200..9999:pnl_normresistor.Caption := '10 KOhm';
6800..8199:pnl_normresistor.Caption := '8,2 KOhm';
5600..6799:pnl_normresistor.Caption := '6,8 KOhm';
4700..5599:pnl_normresistor.Caption := '5,6 KOhm';
3900..4699:pnl_normresistor.Caption := '4,7 KOhm';
3300..3899:pnl_normresistor.Caption := '3,9 KOhm';
2200..3299:pnl_normresistor.Caption := '3,3 KOhm';
end;
 {else
  case trunc(resistor*10) of
    1..12://ist (0.1)..(1.2)     alles mit kommastellen hier rein
  end;
}
 begin
if (Resistor)>2200 then begin
  if (Resistor)<3301 then
pnl_normresistor.Caption := (floattostr(2.2)+' KOhm')
end;
 end;
 begin
if (Resistor)>1625 then begin
  if (Resistor)<2201 then
pnl_normresistor.Caption := (floattostr(1.8)+' KOhm')
end;
 end;
 begin
if (Resistor)>1500 then begin
  if (Resistor)<1626 then
pnl_normresistor.Caption := (floattostr(1.5)+' KOhm')
end;
 end;


usw......
 end;

_frank_ 19. Aug 2006 11:28

Re: Wie kann ich das rechnen
 
Zitat:

Zitat von Gehstock
Delphi-Quellcode:
wert : string;
widerstand : string;
tolerance: string;
...
if cb_ring3.ItemIndex = 0 then widerstand := floattostr((strtofloat(wert)/100));

MAN RECHNET NICHT MIT STRINGS!!!!!!!!!
.oO(ist denn das so schwer zu verstehen?) :gruebel: :wall:

sorry admins, war jetzt mal nötig...

@gehstock: bring erstmal das in ordnung...(und danach die Einrückungen, damit dein Code lesbar wird)

Gruß Frank

Klaus01 19. Aug 2006 11:35

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
if rb_4rings.Checked then
begin                     ++++++wollte ich umstellen (case) tut dann aber auch dumm
  wert := floattostr(((cb_ring1.ItemIndex+1)*10) + cb_ring2.ItemIndex);
  if cb_ring3.ItemIndex = 0 then widerstand := floattostr((strtofloat(wert)/100));
  if cb_ring3.ItemIndex = 1 then widerstand := floattostr((strtofloat(wert)/10));
  if cb_ring3.ItemIndex = 2 then widerstand := floattostr((strtofloat(wert)*1));
  if cb_ring3.ItemIndex = 3 then widerstand := floattostr((strtofloat(wert)*10));
  if cb_ring3.ItemIndex = 4 then widerstand := floattostr((strtofloat(wert)*100));
  if cb_ring3.ItemIndex = 5 then widerstand := floattostr((strtofloat(wert)*1000));
  if cb_ring3.ItemIndex = 6 then widerstand := floattostr((strtofloat(wert)*10000));
  if cb_ring3.ItemIndex = 7 then widerstand := floattostr((strtofloat(wert)*100000));
  if cb_ring3.ItemIndex = 8 then widerstand := floattostr((strtofloat(wert)*1000000));
  if cb_ring3.ItemIndex = 9 then widerstand := floattostr((strtofloat(wert)*10000000));
end;
eine Rechnung durch 100 entspricht einer Multiplikation mit 0.01 // ItemIndex = 0
eine Rechnung durch 10 entspricht einer Multiplikation mit (0.01 *10^1) -> 0.1 // ItemIndex = 1
eine Rechnung * 1 entspricht einer Multiplikation mit (0.01 *10^2) -> 1 // ItemIndex = 2

->

wenn dann wert ein Typ float ist
und widerstand auch

Delphi-Quellcode:
if rb_4rings.checked then
  begin
    wert := ((cb_ring1.ItemIndex+1)*10) + cb_ring2.ItemIndex;

    widerstand := wert * 0.01 * power(10,cb_rings3.ItemIndex);
  end;
Ist etwas kürzer und hoffentlich auch richtig.
Habe es nicht ausprobiert.

Grüße
Klaus

Gehstock 19. Aug 2006 12:06

Re: Wie kann ich das rechnen
 
Ist es Danke
ging ja alles von ganz alleine auser die toleranz

Delphi-Quellcode:
procedure TForm2.btn_executeClick(Sender: TObject);
var
wert : extended;
widerstand : extended;
tolerance: extended;
prozent: extended;

begin
if rb_4rings.Checked then begin
wert := ((cb_ring1.ItemIndex+1)*10) + cb_ring2.ItemIndex;
widerstand := wert * 0.01 * power(10,cb_ring3.ItemIndex);
 end;

if rb_5rings.Checked then begin
wert := ((cb_ring1.ItemIndex+1)*100) +((cb_ring1.ItemIndex+1)*10) + cb_ring2.ItemIndex;
widerstand := wert * 0.01 * power(10,cb_ring54.ItemIndex);
 end;
begin
if (widerstand)>=1000000 then begin
pnl_result.caption := (floattostr((widerstand)/1000000))+' MOhm';
pnl_worstcasemin.caption := '?';
pnl_worstcasemax.caption := '?';
 end;
if (widerstand)>=1000  then begin
 if (widerstand)<1000000  then begin
pnl_result.caption := (floattostr((widerstand)/1000))+' KOhm';
pnl_worstcasemin.caption := '?';
pnl_worstcasemax.caption := '?';
 end;
  end;
if (widerstand)<1000 then begin
pnl_result.caption := (floattostr((widerstand)/1))+' Ohm';
pnl_worstcasemin.caption := (floattostr((widerstand)/1-(tolerance)))+' Ohm';               +++++da ist der Fehler
pnl_worstcasemax.caption := (floattostr((widerstand)/1+(tolerance)))+' Ohm';               ?????falsche klammer
 end;
tolerance := (widerstand)/100*(prozent);
if rb_5rings.Checked then begin

if cb_ring55.ItemIndex = 0 then begin
pnl_Tolerance.Caption:= '5%';
prozent:=(5);
 end;
if cb_ring55.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=(1);
 end;
if cb_ring55.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=(2);
 end;
if cb_ring55.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=(0.5);
 end;
if cb_ring55.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=(0.25);
 end;
if cb_ring55.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=(0.1);
 end;
 end;

if rb_4rings.Checked then begin

if cb_ring4.ItemIndex = 0 then begin
pnl_Tolerance.Caption:= '10%';
prozent:=(10);
 end;
if cb_ring4.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '5%';
prozent:=(5);
 end;
if cb_ring4.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=(1);
 end;
if cb_ring4.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=(2);
 end;
if cb_ring4.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=(0.5);
 end;
if cb_ring4.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=(0.25);
 end;
if cb_ring4.ItemIndex = 6 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=(0.1);
end;
 end;
  end;
   end;

Klaus01 19. Aug 2006 12:13

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
if (widerstand)<1000 then
  begin
    pnl_result.caption := floattostr(widerstand)+' Ohm';
    pnl_worstcasemin.caption := floattostr(widerstand-tolerance)+' Ohm';               +++++da ist der Fehler
    pnl_worstcasemax.caption := floattostr(widerstand +tolerance)+' Ohm';               ?????falsche klammer
  end;
Du hast ja anscheinend eine Klammermanie, soviele unnötige Klammern, da
kommt man schon durcheinander.

Grüße
Klaus


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:10 Uhr.
Seite 2 von 4     12 34      

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