How to Validate Double Value in VB.Net

This tutorial is all about How to Validate Double Value in VB.Net. With this tutorial you can Validate Double Value in VB.Net easily. So let’s get started:

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • Design your form like this just like what I’ve shown you below.
    Add a Label, Button and Textbox.

  • Add this following function.
    [vbnet]
    Function validateDoublesAndCurrency(ByVal stringValue As String) As Boolean
    Dim rslt As Boolean = False
    Dim value As Double
    Dim valueToTest As String = stringValue
    TryvalueToTest = Double.Parse(stringValue, Globalization.NumberStyles.Currency)
    Catch ex As ExceptionEnd Try

    If Double.TryParse(valueToTest, value) Then

    rslt = True
    Else

    rslt = False
    End If
    Return rslt
    End Function

    [/vbnet]

  • Then add this code to the button.
    [vbnet]
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If validateDoublesAndCurrency(TextBox1.Text) = False Then
    MsgBox(“Price entered is not valid”)
    Else
    MsgBox(“Price is Valid”)
    End If
    End Sub
    [/vbnet]
  • Finally, Click F5 to run.

Output:

 

If you have any comments or suggestion about on How to Validate Double Value in VB.Net, Please Feel Free to contact our webpage.

Download How to Validate Double Value in VB.Net Code Here

Other articles you might read also:

 

 

Leave a Comment