Search code examples
.netvb.nettype-conversiondecimalmaskedinput

The Conversion to type Double is not valid?


I have an error in VB.net If CurrencyHolder.Text > 0 And CurrencyHolder.Text < 10000 Then

I am using a Maskedinputbox 00000.00 When I perform my code and the Maskedinputbox is empty I get the following error:

**Tried my best to translate it!!!:$ ) The Conversion of signstreak . to type double is not valid

How can I fix this?


Solution

  • You can use val() : - Returns the numbers contained in a string as a numeric value of appropriate type.

    If Val(CurrencyHolder.Text) > 0 AndAlso Val(CurrencyHolder.Text) < 1000 Then
                'code
            End If
    

    caveats

    val() consider only . to check for a decimal separator incase the end user's lcoale style of decimal point is other than . this will not work