Delphi-PRAXiS

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)

Gehstock 2. Aug 2006 19:17


Wie kann ich das rechnen
 
soll so rechnen (cb_ring1.ItemIndex*10)+cb_ring2.ItemIndex

Delphi-Quellcode:
daten := floattostr(((strtofloat(cb_ring1.ItemIndex)*10)+
strtofloat(cb_ring2.ItemIndex)));
cb_ring1 sind also die 10ér stellen
cb_ring2 sind die 1ér

klappt aber nicht

fwsp 2. Aug 2006 19:19

Re: Wie kann ich das rechnen
 
und was klappt nicht? gibt es nen fehler?

mkinzler 2. Aug 2006 19:19

Re: Wie kann ich das rechnen
 
.ItemIndex ist normalerweise in Integer ;-)

Martin K 2. Aug 2006 19:20

Re: Wie kann ich das rechnen
 
Ich weiß zwar nicht was cb_ring1 und cb_ring2 ist, aber ItemIndex sollte im Normalfall ein Integer sein.
Also warum StrToFloat ???
Delphi-Quellcode:
daten := IntToStr((cb_ring1.ItemIndex*10) + cb_ring2.ItemIndex);
//Edit:
Dann recht auch IntToStr!

TBx 2. Aug 2006 19:55

Re: Wie kann ich das rechnen
 
Hallo!

Kann es sein, daß Du hier zwei Comboboxen mit den Ziffern [0..9] gefüllt hast und nun den Wert ermitteln willst, den der Benutzer eingestellt hat?

Dann muss das so sein:

Delphi-Quellcode:
daten := (StrToInt (cb_ring1.Items[cb_ring1.ItemIndex])) * 10
       + (StrToInt (cb_ring2.Items[cb_ring2.ItemIndex]));
hope it helps

onlinekater

Gehstock 2. Aug 2006 20:30

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
daten := IntToStr((cb_ring1.ItemIndex*10) + cb_ring2.ItemIndex);
klappt einwandfre

nächstes problem

prozentrechnung

Delphi-Quellcode:
if StrTofloat(wiederstand)<1000 then begin
pnl_result.caption := (floattostr((strtofloat(wiederstand)/    ///wiederstand ist ne variable
1))+' Ohm');// der genaue wert
pnl_worstcasemin.caption := (floattostr((strtofloat(wiederstand)/
???????))+' Ohm');// der minimale wert
pnl_worstcasemax.caption := (floattostr((strtofloat(wiederstand)/
???????))+' Ohm');// der maximale wert

end;

if rb_4rings.Checked then begin
if cb_ring4.ItemIndex = 0 then pnl_Tolerance.Caption:= '10%';  // und hier sind die toleranzen
if cb_ring4.ItemIndex = 1 then pnl_Tolerance.Caption:= '5%' ;
if cb_ring4.ItemIndex = 2 then pnl_Tolerance.Caption:= '1%' ;
if cb_ring4.ItemIndex = 3 then pnl_Tolerance.Caption:= '2%' ;
if cb_ring4.ItemIndex = 4 then pnl_Tolerance.Caption:= '0,5%';
if cb_ring4.ItemIndex = 5 then pnl_Tolerance.Caption:= '0,25%';
if cb_ring4.ItemIndex = 6 then pnl_Tolerance.Caption:= '0,1%' ;
end;
if rb_5rings.Checked then begin
if cb_ring55.ItemIndex = 0 then pnl_Tolerance.Caption:= '5%';
if cb_ring55.ItemIndex = 1 then pnl_Tolerance.Caption:= '1%' ;
if cb_ring55.ItemIndex = 2 then pnl_Tolerance.Caption:= '2%' ;
if cb_ring55.ItemIndex = 3 then pnl_Tolerance.Caption:= '0,5%' ;
if cb_ring55.ItemIndex = 4 then pnl_Tolerance.Caption:= '0,25%';
if cb_ring55.ItemIndex = 5 then pnl_Tolerance.Caption:= '0,1%';
end;
end;

mkinzler 2. Aug 2006 20:38

Re: Wie kann ich das rechnen
 
Ich würde den Widerstand in einer (Extended)-variablen zwischenspeichern und dann mit dieser Weiterrechnen.
Die erste Zeile kannst du vereinfachen, indem du den String nimmst und ' Ohm' hinzufügst den eine Zahl durch ein ergibt ja die Zahl ;-)

Wie berechnen sich die anderen Werte ( minimal + maximal)? und was daß mit Prozentrechnung zu tun?

fwsp 2. Aug 2006 20:38

Re: Wie kann ich das rechnen
 
ich würde dir als erstes emphelen dir mal den styleguide auf dsdt.info anzugucken. desweiteren solltest du zur besseren übersicht einmal die variable aus der combo ziehen und dann mit case weiterarbeiten.

Delphi-Quellcode:

var
  x: extended;
begin
  if rb_4rings.Checked then
  begin
    x := cb_ring4.ItemIndex
    case x of
      0: pnl_Tolerance.Caption:= '10%';  // und hier sind die toleranzen
      1: pnl_Tolerance.Caption:= '5%' ;
      2: pnl_Tolerance.Caption:= '1%' ;
      3: pnl_Tolerance.Caption:= '2%' ;
      4: pnl_Tolerance.Caption:= '0,5%';
      5: pnl_Tolerance.Caption:= '0,25%';
      6: pnl_Tolerance.Caption:= '0,1%' ;
    end;
  end;
end;
sieht doch schon mal besser aus, oder?

Gehstock 3. Aug 2006 17:23

Re: Wie kann ich das rechnen
 
Delphi-Quellcode:
tolerance := floattostr((strtofloat((pnl_result.caption)/100)*prozent));
kann mir das jemand so umstellen das es klappt

fkerber 3. Aug 2006 18:12

Re: Wie kann ich das rechnen
 
Hi!

Könntest du bitte deinem Thread noch einen aussagekräftigen Titel geben? Darunter kann man sich nur wenig vorstellen!


Ciao, Frederic

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

_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

Gehstock 19. Aug 2006 13:21

Re: Wie kann ich das rechnen
 
Liste der Anhänge anzeigen (Anzahl: 1)
OkoOk
war doppeltgemoppelt :mrgreen:
hat denn aber keiner ne idee :gruebel: was den Fehler angeht

Fehler in den Variablen???
Delphi-Quellcode:
wert : extended;
widerstand : extended;
prozent: extended;

Zitat:

warum denn die 1?
weil ich ja noch andere einheiten habe so lässt sich die formel schneller anpassen

Hawkeye219 19. Aug 2006 13:24

Re: Wie kann ich das rechnen
 
Zitat:

Zitat von Gehstock
Ergebnis bleibt das selbe

Siehe Beitrag #23. Du hast lediglich eine nicht initialisierte Variable (tolerance) durch eine andere nicht initialisierte Variable (prozent) ersetzt...

Gruß Hawkeye

Gehstock 19. Aug 2006 13:31

Re: Wie kann ich das rechnen
 
Zitat:

Siehe Beitrag #23. Du hast lediglich eine nicht initialisierte Variable (tolerance) durch eine andere nicht initialisierte Variable (prozent) ersetzt...

:bounce1: JaJa das wars Danke :bounce1:

mkinzler 19. Aug 2006 13:33

Re: Wie kann ich das rechnen
 
Zitat:

Zitat:
warum denn die 1?

weil ich ja noch andere einheiten habe so lässt sich die formel schneller anpassen
dann würde ich das gleich mit einer Variablen machen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:09 Uhr.

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