![]() |
If not XY in [...] mit reellen Typen
Hallo DP,
ich muss einen Radius mit einer Werkzeugliste vergleichen. Wenn der "Radius" nicht in der Liste vorhanden ist, soll ein Fehler ausgegeben werden. Zur Zeit verwende ich diesen Code.
Delphi-Quellcode:
Der Code funktioniert, die Schreibweise gefällt mir jedoch nicht.
var
Radius : extended; . . . Radius := StrToFloat(Form1.StringGrid1.Cells[4, i]); if Radius <> 3.4 then if Radius <> 4.25 then if Radius <> 5.1 then if Radius <> 6 then if Radius <> 7 then if Radius <> 8.75 then if Radius <> 10.5 then if Radius <> 13.25 then if Radius <> 16 then begin Form1.StringGrid1.Cells[9, i] := 'ERROR'; end; Ich suche eher etwas wie
Delphi-Quellcode:
Habt ihr eine Idee wie der Code vereinfacht werden kann?
if not (Radius in [1,2,3]) then ...
|
Re: If not XY in [...] mit reellen Typen
Das ist "Case". -> OH
|
Re: If not XY in [...] mit reellen Typen
Zitat:
Was du (mal ganz spezifisch den fall betrachtet) tun könntest wäre folgendes: statt
Delphi-Quellcode:
dasda
Radius := StrToFloat(Form1.StringGrid1.Cells[4, i]);
if Radius <> 3.4 then if Radius <> 4.25 then if Radius <> 5.1 then if Radius <> 6 then if Radius <> 7 then if Radius <> 8.75 then if Radius <> 10.5 then if Radius <> 13.25 then if Radius <> 16 then begin Form1.StringGrid1.Cells[9, i] := 'ERROR'; end;
Delphi-Quellcode:
schreiben
Radius: integer;
Radius := round(StrToFloat(Form1.StringGrid1.Cells[4, i]) * 100); if not (Radius in [340, 425, 510, 600, 700, 875, 1050, 1325, 1600]) then Form1.StringGrid1.Cells[9, i] := 'ERROR'; Oder du schreibst dir eine Funktion:
Delphi-Quellcode:
function IsWertIn(Wert: extended; Werte: array of extended): boolean;
begin result := true; for i := 0 to high(Werte) do if Wert = Werte[i] then //vorsicht hier: extendeds vergleichen sollte man nicht, sondern mit einer abweichung von +/- 0.josef vergleichen exit; result := false; end; |
Re: If not XY in [...] mit reellen Typen
Zitat:
|
Re: If not XY in [...] mit reellen Typen
Delphi-Quellcode:
Das sieht gut aus...
Radius: integer;
Radius := round(StrToFloat(Form1.StringGrid1.Cells[4, i]) * 100); if not (Radius in [340, 425, 510, 600, 700, 875, 1050, 1325, 1600]) then Form1.StringGrid1.Cells[9, i] := 'ERROR'; Danke |
Re: If not XY in [...] mit reellen Typen
Zitat:
also wenn du +/-.adolf geschrieben hättest, würd ich mir ja sorgen um dich machen, Chimaira, aber so hab ich einfach null ahung, was du meinst.... |
Re: If not XY in [...] mit reellen Typen
wen ner aus österreich kommt hats ne bedeutung :)
sagt man so 0 komma josef ;) |
Re: If not XY in [...] mit reellen Typen
Er hätte auch +/- 0.x schreiben können. Hauptsache, du gibst ein bestimmtes Intervall an, in dem sich die Werte befinden müssen.
|
Re: If not XY in [...] mit reellen Typen
ah sehr schön. muss ich doch noch ne fremdsprache lernen. :lol:
|
Re: If not XY in [...] mit reellen Typen
abseits noch ne frage
ordinal und primitiv ist dasselbe oder? |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:36 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