Einzelnen Beitrag anzeigen

Klaus01
Online

Registriert seit: 30. Nov 2005
Ort: München
5.757 Beiträge
 
Delphi 10.4 Sydney
 
#18

Re: Wie kann ich das rechnen

  Alt 19. Aug 2006, 11:35
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
Klaus
  Mit Zitat antworten Zitat