```
If not a=0 then begin
If ((b<>0) and (a<=b)) and ((c<>0) and (a<=c)) and ((d<>0) and (a<=d)) and ((e<>0) and (a<=e)) and ((g<>0) and (a<=g)) then
richeditWriteOKcursor:=true;
end;
```

Solved

Posted on 2008-11-11

How to make code below to not consider into "if" statment variables b,c,d,e,g if them value is zero?

example:

b=0

example:

b=0

```
If not a=0 then begin
If (a<=b) and (a<=c) and (a<=d) and (a<=e) and (a<=g) then
richeditWriteOKcursor:=true;
end;
```

19 Comments

```
If not a=0 then begin
If ((b<>0) and (a<=b)) and ((c<>0) and (a<=c)) and ((d<>0) and (a<=d)) and ((e<>0) and (a<=e)) and ((g<>0) and (a<=g)) then
richeditWriteOKcursor:=true;
end;
```

```
If ( a = 0) or ( b = 0) or ( c = 0) or ( d = 0) or ( e = 0) then exit;
If (a<=b) and (a<=c) and (a<=d) and (a<=e) and (a<=g) then
richeditWriteOKcursor:=true;
```

richeditWriteOKcursor:=tru

Variable richeditWriteOKcursor must be also true if b,c,d,e,g are zero.

```
if not ( a = 0) then
if ( ( b = 0) or ( c = 0) or ( d = 0) or ( e = 0)) or
( ( a <= b) and ( a <= c) and ( a <= d) and ( a <= e)) then
richeditWriteOKcursor:=true;
end;
```

Maybe it might be this instead, just a little hard to understand your exact logic.

```
if not ( a = 0) then
if ( ( b = 0) and ( c = 0) and ( d = 0) and ( e = 0)) or
( ( a <= b) and ( a <= c) and ( a <= d) and ( a <= e)) then
richeditWriteOKcursor:=true;
```

```
if not ( a = 0) then
richeditWriteOKcursor := ( ( b = 0) and ( c = 0) and ( d = 0) and ( e = 0)) or ( ( a <= b) and ( a <= c) and ( a <= d) and ( a <= e))
```

```
if not ( a = 0) then
if ( ( b <> 0) and ( a <= b)) or
( ( c <> 0) and ( a <= c)) or
( ( d <> 0) and ( a <= d)) or
( ( e <> 0) and ( a <= e)) or
( ( g <> 0) and ( a <= g)) then
richeditWriteOKcursor := true;
```

```
if not ( a = 0) then
if ( ( b <> 0) and ( a > b)) or
( ( c <> 0) and ( a > c)) or
( ( d <> 0) and ( a > d)) or
( ( e <> 0) and ( a > e)) or
( ( g <> 0) and ( a > g)) then
richeditWriteOKcursor := true;
```

function OK(a, x: integer): boolean;

begin

result := (x <> 0) and (a > x);

end;

then the main part would go:

RichEditWriteOKCursor := (a <> 0) and OK(a,b) or OK(a,c) or OK(a,d) or OK(a,e) or OK(a,g);

or alternatively, a slight longer way (same results):

if a = 0

then RichEditWriteOKCursor := false

else RichEditWriteOKCursor := OK(a,b) or OK(a,c) or OK(a,d) or OK(a,e) or OK(a,g);

Thats why I tend to space out the conditionals like I do and keep like for like together.

you could use this

if you want a to be bigger than all other variables then a is the biggest

function Biggest(Values: Variant): Variant;

var I: Integer;

begin

Result := 0;

for I := VarArrayLowBound(Values, 1) to VarArrayHighBound(Values, 1) do

if (Values[I] <> 0) and (Values[I] > Result) then

Result := Values[I];

end;

use it like

RichEditWriteOKCursor := (a <> 0) and (a = Biggest(VarArrayCreate([a,

if A must be less than or equal to all of the non zero values then it stands to reason that it must be less than or equal to the least of the individual non zero values. The second statement would be functionally equivalent while changing the means of implementing it. This is pseudocode, but you should get the idea.

procedure MeEvent(Sender : TObject);

var

Min : integer;

procedure Adjust(val : integer);;

begin

if Min = 0 then

min := val

else

if val < min then

min := val;

end;

richeditWriteOKcursor := false;

If a <> 0 then

begin

min := 0;

Adjust(b);

Adjust(c);

Adjust(d);

Adjust(e);

Adjust(g);

{min will only be zero if all are zero}

If (min <> 0) and (a <= min) then

richeditWriteOKcursor:=tru

end;

The code above does what i need.

(when "a" is less (sorry for wrong information before) than other variables and

it looks only variables which are not zero)

thank you

```
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Shape1: TShape;
Button1: TButton;
a: TLabel;
b: TLabel;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
richeditWriteOKcursor :bool;
a,b,c,d,e,g,min: integer;
implementation
{$R *.dfm}
procedure Adjust(val : integer);
begin
if Min = 0 then
min := val
else
if val < min then
min := val;
end;
procedure MeEvent();
begin
a:=strtoint(form1.edit1.text);
b:=strtoint(form1.edit2.text);
c:=strtoint(form1.edit3.text);
richeditWriteOKcursor := false;
If a <> 0 then begin
min := 0;
Adjust(a);
Adjust(b);
Adjust(c);
{min will only be zero if all are zero}
If (min <> 0) and (a <= min) then
richeditWriteOKcursor:=true;
if richeditWriteOKcursor then form1.Shape1.Brush.Color:=clgreen else form1.Shape1.Brush.Color:=clred;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MeEvent();
end;
end.
```

you are mixing 2 types of coding and using very bad variable / component naming

have you tried your example with a = 1, b = 5, c = 10 ?

min := 0;

Adjust(a); // min = 1

Adjust(b); // min = 1

Adjust(c); // min = 1

If (min <> 0) and (a <= min) then

richeditWriteOKcursor:=tru

and with a = 5, b = 10, c = 1

min := 0;

Adjust(a); // min = 5

Adjust(b); // min = 5

Adjust(c); // min = 1

If (min <> 0) and (a <= min) then

richeditWriteOKcursor:=tru

a evaluation of your code resulted in this very short piece of code

with no extra functions except from the math unit

```
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
EditA: TEdit;
EditB: TEdit;
EditC: TEdit;
Shape1: TShape;
Button1: TButton;
lblA: TLabel;
lblB: TLabel;
lblC: TLabel;
procedure Button1Click(Sender: TObject);
private
FRicheditWriteOKcursor :bool;
public
end;
var
Form1: TForm1;
implementation
uses Math;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const BrushColors: Array[Boolean] of TColor = (clRed , clGreen); // clRed = False, clGreen = True
var a, b, c, x: integer;
begin
a := strtoint(editA.text);
b := strtoint(editB.text);
c := strtoint(editC.text);
x := min(a, ifthen(b>0, b, a));
x := min(x, ifthen(c>0, c, x));
FRicheditWriteOKcursor := (x > 0) and (a = x);
Shape1.Brush.Color := BrushColors[FRicheditWriteOKcursor];
end;
end.
```

Title | # Comments | Views | Activity |
---|---|---|---|

DevExpress VLC activate lookandfeel | 5 | 118 | |

Convert Jpg /PNG To GIF | 5 | 81 | |

QRReport TQrmemo vertical stretching | 1 | 28 | |

Convert a string into a TDateTime | 5 | 26 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**24** Experts available now in Live!