Android Question width = width*(pct*(width>height)) ... Possible?

Marc De Loose

Member
Licensed User
Longtime User
I would like to write:
width = width*(pct*(width>height))

what would resolve to:
(if width is greater than height)
width = width*(pct*1)

if not
width = width *(pct*0)

is width = width*(pct*(width>height)) somehow possible?
 
or make this boolean a number
Code:
Sub Test

    Dim width,height,pct As Float
    width = 200
    height  =100
    pct = 5
    
    width = width*(pct*B(width>height))

    Log(width)

End Sub

Sub B(truefalse As Boolean) As Float
    
    If truefalse Then Return 1.0 Else Return 0.0
        
End Sub
 
Upvote 0
I would like to write:
width = width*(pct*(width>height))

what would resolve to:
(if width is greater than height)
width = width*(pct*1)

if not
width = width *(pct*0)


I'd be inclined to just go with:
Code:
if width > height then
    width = width * pct
else
    width = 0
end if
which I feel wins on simplicity, efficiency and brevity, but if you must have it as one statement (if we ignore the called function...) then LucaMs wins:
Code:
width = IIF(width > height, width * pct, 0)
with Brandsum in a close but cryptic second place, assuming width and height are integers ;-)
 
Last edited:
Upvote 0
Back
Top