Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Anfängerhilfe -> if bedingung (https://www.delphipraxis.net/147963-anfaengerhilfe-if-bedingung.html)

Sannes 19. Feb 2010 19:27


Anfängerhilfe -> if bedingung
 
Hi,

Erstmall toll das man hier Hilfe bekommen kann :thumb:

Naja mein Problem versteh ich selbst nich so ganz, sollte eigentlich funken, tuts aber nich!

Delphi-Quellcode:
if (i = ListBox2.Items.Count -1) or ((not StrToInt(ComboBox2.Text) = 0) and (StrToInt(ComboBox2.Text) = h)) then ...
Die i = ListBox2.Items.Count bedingung wird erfüllt. Diese soll unabhängig von den beiden anderen Bedingungen sein.
Bei der anderen handelt es sich um ein auswählbaren Wert in der Combobox zwischen 0 und 10. Die Bedingung soll aber nur erfüllt werden wenn die Variable h den Wert in der Combobox entspricht und dieser auch nicht 0 ist.

Ich habe mir den Wert ComboBox2.Text und h schon in einer Listbox ausgeben lassen, h überschreitet einfach den Combobox wert ohne das die Bedingung erfüllt wird.

Hoffe ich bin nich allzu doof dafür :o

greetz Sannes

mkinzler 19. Feb 2010 19:36

Re: Anfängerhilfe -> if bedingung
 
If verstehe nicht ganz, wann die Bedingung war sein soll
Soll die 1. Bedingung nund eine der anderen wahr sein?

BUG 19. Feb 2010 19:39

Re: Anfängerhilfe -> if bedingung
 
not ist nicht nur ein Operator für Booleanwerte, sondern auch für Integer.
Dort bildet not die bitweise Negation.

Um das zu vermeiden, benutze entweder eine Klammer mehr:
Delphi-Quellcode:
if (i = ListBox2.Items.Count -1) or ((not (StrToInt(ComboBox2.Text) = 0)) and (StrToInt(ComboBox2.Text) = h)) then
oder vergleiche anders und lass not weg:
Delphi-Quellcode:
if (i = ListBox2.Items.Count -1) or ((StrToInt(ComboBox2.Text) <> 0) and (StrToInt(ComboBox2.Text) = h)) then

Ich hoffe, ich habe richtig verstanden, was du willst :mrgreen:

Sannes 19. Feb 2010 20:24

Re: Anfängerhilfe -> if bedingung
 
Zitat:

Zitat von BUG
not ist nicht nur ein Operator für Booleanwerte, sondern auch für Integer.
Dort bildet not die bitweise Negation.

Um das zu vermeiden, benutze entweder eine Klammer mehr:
Delphi-Quellcode:
if (i = ListBox2.Items.Count -1) or ((not (StrToInt(ComboBox2.Text) = 0)) and (StrToInt(ComboBox2.Text) = h)) then
oder vergleiche anders und lass not weg:
Delphi-Quellcode:
if (i = ListBox2.Items.Count -1) or ((StrToInt(ComboBox2.Text) <> 0) and (StrToInt(ComboBox2.Text) = h)) then

Ich hoffe, ich habe richtig verstanden, was du willst :mrgreen:

Dankeschön BUG, funktioniert einwandfrei =) :angel:

himitsu 19. Feb 2010 20:27

Re: Anfängerhilfe -> if bedingung
 
Zitat:

Delphi-Quellcode:
if (i = ListBox2.Items.Count -1) or ((StrToInt(ComboBox2.Text) <> 0) and (StrToInt(ComboBox2.Text) = h)) then

Wobei man hier noch etwas kürzen und eine Stringoperation loswerden kann
Delphi-Quellcode:
if (i = ListBox2.Items.Count - 1) or ((h <> 0) and (StrToInt(ComboBox2.Text) = h)) then

haentschman 20. Feb 2010 06:52

Re: Anfängerhilfe -> if bedingung
 
Die Jungs haben es völlig vergessen...

herzlich willkommen in der DP :dp:

PS: daß du if Bedingung geschrieben hast und nicht if.... (ich sags lieber nicht sonst muß ich ein :cheers: ausgeben) ist :thumb:


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:58 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