How to Validate the TextBox using ErrorProvider in VB.NET
This tutorial is all about How to Validate the TextBox using ErrorProvider in VB.NET.
In this tutorial, I will teach you how to validate a Textbox using an ErrorProvider in VB.NET. This will help you know what are the inputs that you’re going to put in the TextBox and it will inform you if the errors will occur.
What is Visual Basic’s purpose?
The third-generation programming language was created to aid developers in the creation of Windows applications. It has a programming environment that allows programmers to write code in.exe or executable files. They can also utilize it to create in-house front-end solutions for interacting with huge databases. Because the language allows for continuing changes, you can keep coding and revising your work as needed.
However, there are some limits to the Microsoft Visual Basic download. If you want to make applications that take a long time to process, this software isn’t for you. That implies you won’t be able to use VB to create games or large apps because the system’s graphic interface requires a lot of memory and space. Furthermore, the language is limited to Microsoft and does not support other operating systems.
What are the most important characteristics of Visual Basic?
Microsoft Visual Basic for Applications Download, unlike other programming languages, allows for speedier app creation. It has string processing capabilities and is compatible with C++, MFC, and F#. Multi-targeting and the Windows Presentation Framework are also supported by the system, allowing developers to create a variety of Windows apps, desktop tools, metro-style programs, and hardware drivers.
- Step 1: Open the Visual Basic and create a new Windows Form Application.
- Step 2: Drag the two TextBoxes, a Button and an Error Provider in the Form. And it will look like this.
3. Step 3: After setting up the Form, double click the Button and put the codes into the click event handler of the Button.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'CHECKING IF THE TWO TEXTBOXES ARE CLEARED. If txt_string.Text = "" And txt_integer.Text = "" Then 'THE ERROR PROVIDER WILL APPEAR AND IT WILL INFORM THE PROBLEM TO THE USER. ErrorProvider1.SetError(txt_string, "Textbox must be filled up.") ErrorProvider1.SetError(txt_integer, "Textbox must be filled up.") Else 'SET THE ERROR PROVIDER TO BE CLEARED. ErrorProvider1.SetError(txt_string, "") ErrorProvider1.SetError(txt_integer, "") 'CHECKING IF YOU HAVE INPUT A NUMERIC VALUE. If IsNumeric(txt_string.Text) Then 'THE ERROR PROVIDER WILL APPEAR AND IT WILL INFORM THE PROBLEM TO THE USER. ErrorProvider1.SetError(txt_string, "You have input a numeric value that is not valid.") Else 'SET THE ERROR PROVIDER TO BE CLEARED. ErrorProvider1.SetError(txt_string, "") End If 'CHECKING IF YOU HAVE INPUT A STRING VALUE. If Not IsNumeric(txt_integer.Text) Then 'THE ERROR PROVIDER WILL APPEAR AND IT WILL INFORM THE PROBLEM TO THE USER. ErrorProvider1.SetError(txt_integer, "You have input a string value that is not valid.") Else 'SET THE ERROR PROVIDER TO BE CLEARED. ErrorProvider1.SetError(txt_integer, "") End If End If End Sub
You can download the complete source code of TextBox Validation using ErrorProvider Here.
What we have done here in this tutorial is that we learn how to write program code to perform the data validation using error provider control.