3

Is there a built in VB function to ensure the following:

Dim price
Dim subsidy

if price - subsidy <= 0 then 
    price = 0
end if

In practical terms, I've lots of other things going on to calculate price, so I want to simplify this to:

Dim price = calculatedPrice - subsidy

and wrap that into some VB formatting that ensures if price ever becomes negative it's forced to zero.

I'm thinking that a simple type conversion might do it, but am not sure which type would suit.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Jamie Hartnoll
  • 7,231
  • 13
  • 58
  • 97

1 Answers1

5

You can use Math.Max to do it:

Dim price = Math.Max(calculatedPrice - subsidy, 0)
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523