TextBox Control

Submitted by: 
Visitors have accessed this post 4780 times.

One of the most common control used in visual basic is a text box. The main purpose of textbox is that, it allows user to input text information to be used by the program. By default, text box takes a single line of text. But using visual basic, you can set the property to accept a multiple line of text and even with a scroll bar.

This time, open visual basic and create a new project called “Textbox”. Then drag a six text box and six label from the toolbox. And arrange all the objects that look like as shown below.

What we're doing here is a Calculator for Multiplication, Division, Addition and Subtraction, that when the user type the value for the Input 1 and during the encoding the values in Input 2 the program will automatically compute for each operator and display the output in the corresponding text box.

To do this add the following code:

In this code below, we use TextChanged event that triggered when there is any change in the textbox. Then it will automatically compute for our different operators.

  1. Private Sub txtinput2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtinput2.TextChanged
  2. 'will do the computation for multiplication
  3. txtmul.Text = Val(txtinput1.Text) * Val(txtinput2.Text)
  4. 'will do the computation for Division
  5. txtdiv.Text = Val(txtinput1.Text) / Val(txtinput2.Text)
  6. 'will do the computation for Addition
  7. txtadd.Text = Val(txtinput1.Text) + Val(txtinput2.Text)
  8. 'will do the computation for Subtraction
  9. txtsub.Text = Val(txtinput1.Text) - Val(txtinput2.Text)
  11. End Sub

When executing the program, it will give an output that look likes as shown below.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.