Martin_T
(Martin T)
March 11, 2016, 12:51pm
1
Hi everyone,
I habe to following working If...Then
Code:
If Me.VerticalAlign <> VerticalAlignment.None Or Me.VerticalAlign <> VerticalAlignment.Baseline Then
...
End If
Compiler says Error, if i’ll note it this way:
If Me.VerticalAlign <> (VerticalAlignment.None Or VerticalAlignment.Baseline) Then
...
End If
Is there a working way to Compact the Code?
Read again carefully your second code. It cannot work the same as the first one.
Admitting the terms are an integer, what you are doing is a bitwise OR, not a boolean OR.
See http://documentation.xojo.com/index.php/Or
I’m a little brain-dead from overworking lately, but if I’m reading this correctly, your code will always evaluate to TRUE; since Me.VerticalAlign can only be a single value, it will always be not equal to at least one of your conditions
And, to answer your original question, you can’t do what you are trying because
(VerticalAlignment.None Or VerticalAlignment.Baseline)
evaluates to a boolean; you are basically running the following:
Me.VerticalAlign <> True
(or False)
Norman_P
(Norman P)
March 11, 2016, 6:52pm
5
[quote=252634:@Martin Trippensee]Hi everyone,
I habe to following working If...Then
Code:
If Me.VerticalAlign <> VerticalAlignment.None Or Me.VerticalAlign <> VerticalAlignment.Baseline Then
...
End If
Compiler says Error, if i’ll note it this way:
If Me.VerticalAlign <> (VerticalAlignment.None Or VerticalAlignment.Baseline) Then
...
End If
Is there a working way to Compact the Code?[/quote]
The compiler is telling you the answer - no - or at least NOT like you wrote
I’d suggest two things
parens to make it clearer
split the line using continuations
If (Me.VerticalAlign <> VerticalAlignment.None) _
Or (Me.VerticalAlign <> VerticalAlignment.Baseline) Then
...
End If
I agree with Mark.
The test is pointless… it will always be True
Consider it like this:
[code]If 1 <> 2 or 1 <> 1 then
//this always executes
end if[/code]
How about
[code]select case Me.VerticalAlign
case VerticalAlignment.None
case VerticalAlignment.Baseline
case else
//your code goes here
end select[/code]
If this is a specific test you’re doing several places then wrap it in an extension method for something like
if Me.VerticalAlignIsNotNoneOrBaseLine then
//...
end
Martin_T
(Martin T)
March 13, 2016, 6:23pm
8
[quote=252697:@Mark Walsh]And, to answer your original question, you can’t do what you are trying because
(VerticalAlignment.None Or VerticalAlignment.Baseline)
evaluates to a boolean; you are basically running the following:
Me.VerticalAlign <> True
(or False)[/quote]
Thank you Mark and Norman for answering, so i uses Normans tips for the Notation.