• We just launched and are currently in beta. Join us as we build and grow the community.

How to Clear Multiple Textbox in a Smart Way using Visual Basic

shane098

Crypto Community Manager
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
168
Likes
23
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
In this tutorial, I'm going to show how to create an application that will help you to save more time and number of lines of code just to clear your multiple textbox in a single form. This time, let's start building our application:

Step 1.
Create a new project in visual Basic 2008, then design the interface that looks like as shown below:
c1_1.png


Step 2. Double click the “Using "" ” button. Then add the following code:
  1. TextBox1.

    Text

    =

    ""
  2. TextBox2.

    Text

    =

    ""
  3. TextBox3.

    Text

    =

    ""
  4. TextBox4.

    Text

    =

    ""
  5. TextBox5.

    Text

    =

    ""


Explanation:
The added code code in step 2, we simply set the text value of a text to an empty string.

Step 3. Double click the “Using Nothing” button and add the following code:
  1. TextBox1.

    Text

    =

    Nothing
  2. TextBox2.

    Text

    =

    Nothing
  3. TextBox3.

    Text

    =

    Nothing
  4. TextBox4.

    Text

    =

    Nothing
  5. TextBox5.

    Text

    =

    Nothing

Explanation:
The new added code in step 3, we just set the text value of a textbox to Nothing.

Step 4. Double click the “Using Smart Clear” button and add the following code:

  1. For

    Each

    ctrl As

    Control In

    Controls
  2. If

    ctrl.

    GetType

    Is

    GetType

    (

    TextBox)

    Then
  3. ctrl.

    Text

    =

    Nothing
  4. End

    If
  5. Next

Explanation:

In the new added code in step 4, we use “For Each Next loop”. We set a variable “ctrl” as Control in “Controls” to get the collection of control contained within the control. Then we use the conditional logic, if statement to check if the Type of control is Textbox, then it will set the Text property of a textbox into “Nothing”.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

328,328

328,336

Top