Delphi-PRAXiS
Seite 1 von 4  1 23     Letzte »    

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


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:07 Uhr.
Seite 1 von 4  1 23     Letzte »    

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