This function keeps giving me problem I cannot seem to find the right combination to get it working. I am trying to apply discount if certain amount is reached but I keep getting conversion error. What do I need to do so I define everything so it works?
Function coupon() As Decimal
Dim decdiscount As Decimal
Dim inta, intb, intc As Decimal
inta = 20.0
intb = 40.0
intc = 60.0
If lblSubtotal.Text > inta Then
decdiscount = 0.05
End If
If lblSubtotal.Text > intb Then
decdiscount = 0.1
End If
If lblSubtotal.Text > intc Then
decdiscount = 0.2
End If
Return decdiscount
End Function
You really should enable Option Strict for your projects. It would help you avoid the conversion error at runtime by letting you know that you had an implicit conversion when you entered it. You could then use the Decimal.TryParse Method as BluesRockAddict and Andrew Kennan suggest.
From above link:
In your case it would flag the implicit conversions in your code.