Einzelnen Beitrag anzeigen

Benutzerbild von _frank_
_frank_

Registriert seit: 21. Feb 2003
Ort: Plauen / Bamberg
922 Beiträge
 
Delphi 3 Professional
 
#9

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 20:25
Zitat von Gehstock:
...
bitte gewöhne dir ordentliche code-formatierung (Einrückung) an...

(mal davon abgesehen schreibt man widerstand ohne 'e' )

Delphi-Quellcode:
procedure TForm2.btn_executeClick(Sender: TObject);
var
  wert : integer;
  widerstand,prozent,tolerance : double;
  einheit:string;
begin
  if rb_4rings.Checked then
  begin
    wert := (cb_ring1.ItemIndex+1)*10 + cb_ring2.ItemIndex;
    case cb_ring3.ItemIndex of
      0: widerstand := wert/100;
      1: widerstand := wert/10;
      2: widerstand := wert;
      3: widerstand := wert*10;
      4: widerstand := wert*100;
      5: widerstand := wert*1000;
      6: widerstand := wert*10000;
      7: widerstand := wert*100000;
      8: widerstand := wert*1000000;
      9: widerstand := wert*10000000));
    end;

...

  //widerstandswert ausgeben (2 nachkommastellen)
  if wiederstand>999000 then
  begin
    widerstand:=widerstand / 1000000;
    Einheit:='MOhm';
  end else if ...

  pnl_result.caption := format ('%.2f '+einheit,[widerstand]);


...

  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;
  end;

  if rb_5rings.Checked then
  begin
    case cb_ring55.ItemIndex of
      0: prozent:=5;
      1: prozent:=1;
      2: prozent:=2;
      3: prozent:=0.5;
      4: prozent:=0.25;
      5: prozent:=0.1;
    end;
  end;
  pnl_Tolerance.Caption:= FloatToStr(prozent)+' %';
  tolerance := wiederstand/100*prozent;
  pnl_worstcasemin.caption := floattostr(wiederstand-tolerance)+' '+Einheit);
  pnl_worstcasemax.caption := floattostr(wiederstand+tolerance)+' '+Einheit);
end;
HTH Frank
  Mit Zitat antworten Zitat