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.
    1. Function validateDoublesAndCurrency(ByVal stringValue As String) As Boolean
    2. Dim rslt As Boolean = False
    3. Dim value As Double
    4. Dim valueToTest As String = stringValue
    5. TryvalueToTest = Double.Parse(stringValue, Globalization.NumberStyles.Currency)
    6. Catch ex As ExceptionEnd Try
    8. If Double.TryParse(valueToTest, value) Then
    10. rslt = True
    11. Else
    13. rslt = False
    14. End If
    15. Return rslt
    16. End Function
  • Then add this code to the button.
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. If validateDoublesAndCurrency(TextBox1.Text) = False Then
    3. MsgBox("Price entered is not valid")
    4. Else
    5. MsgBox("Price is Valid")
    6. End If
    7. End Sub
  • Finally, Click F5 to run.



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:



Facebook Comments


Please enter your comment!
Please enter your name here