AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

If not XY in [...] mit reellen Typen

Ein Thema von engine · begonnen am 23. Mai 2005 · letzter Beitrag vom 30. Mai 2005
Antwort Antwort
Seite 1 von 2  1 2      
engine

Registriert seit: 6. Mär 2005
73 Beiträge
 
#1

If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 21:42
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:
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;
Der Code funktioniert, die Schreibweise gefällt mir jedoch nicht.
Ich suche eher etwas wie
if not (Radius in [1,2,3]) then ... Habt ihr eine Idee wie der Code vereinfacht werden kann?
  Mit Zitat antworten Zitat
Hansa

Registriert seit: 9. Jun 2002
Ort: Saarland
7.554 Beiträge
 
Delphi 8 Professional
 
#2

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 21:47
Das ist "Case". -> OH
Gruß
Hansa
  Mit Zitat antworten Zitat
Benutzerbild von JasonDX
JasonDX
(CodeLib-Manager)

Registriert seit: 5. Aug 2004
Ort: München
1.062 Beiträge
 
#3

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 21:58
Zitat von Hansa:
Das ist "Case". -> OH
Case funktioniert auch nur mit ordinalen Typen, also nicht mit beispielsweise strings oder floats (=reals)

Was du (mal ganz spezifisch den fall betrachtet) tun könntest wäre folgendes:
statt
Delphi-Quellcode:
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;
dasda
Delphi-Quellcode:
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';
schreiben

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;
Mike
Passion is no replacement for reason
  Mit Zitat antworten Zitat
engine

Registriert seit: 6. Mär 2005
73 Beiträge
 
#4

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 21:58
Zitat von Hansa:
Das ist "Case". -> OH
Ja, "Case" funktioniert prima mit Ordinale Typen, aber nicht mit "extended".
  Mit Zitat antworten Zitat
engine

Registriert seit: 6. Mär 2005
73 Beiträge
 
#5

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 22:10
Delphi-Quellcode:
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';
Das sieht gut aus...

Danke
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#6

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 22:36
Zitat:
+/- 0.josef
AHA?!
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....
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Nicodius

Registriert seit: 25. Apr 2003
Ort: Graz
2.234 Beiträge
 
Delphi 2006 Architect
 
#7

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 22:38
wen ner aus österreich kommt hats ne bedeutung


sagt man so 0 komma josef
Nico Müller
  Mit Zitat antworten Zitat
Benutzerbild von leddl
leddl

Registriert seit: 13. Okt 2003
Ort: Künzelsau
1.613 Beiträge
 
Delphi 2006 Professional
 
#8

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 22:39
Er hätte auch +/- 0.x schreiben können. Hauptsache, du gibst ein bestimmtes Intervall an, in dem sich die Werte befinden müssen.
Axel Sefranek
A programmer started to cuss, cause getting to sleep was a fuss.
As he lay there in bed, looping round in his head
was: while(!asleep()) ++sheep;
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#9

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 22:46
ah sehr schön. muss ich doch noch ne fremdsprache lernen.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Nicodius

Registriert seit: 25. Apr 2003
Ort: Graz
2.234 Beiträge
 
Delphi 2006 Architect
 
#10

Re: If not XY in [...] mit reellen Typen

  Alt 23. Mai 2005, 22:48
abseits noch ne frage


ordinal und primitiv ist dasselbe oder?
Nico Müller
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:21 Uhr.
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