Dreevoo.com | Online Learning and Knowledge Sharing
 
Home | Programs | Programming languages | Visual Basic | My first Visual Basic program
Guest
Click to view your profile
Topics
Programs
Languages
Recipes
Home
Shortcuts
 
 

My first Visual Basic program

In this beginners lesson, we're going to create an application which will copy a text from one field to another by click of a button.

 
  Author: mat | Version: 2010 | 24th October 2011 |  
 
 
1.
 

Open MS Visual Basic 2010, start New Project... and double-click Windows Forms Application.

If you don't have the Visual Basic 2010, click here for the lesson on where to download and how to install it.

 
 
2.
 

A new empty Form ready to be designed and programmed is now open.

 
 
3.
 

First we're going to add two text entry fields.

Click Toolbox button (see picture).

 
 
4.
 

In the Toolbox click TextBox...

 
 
5.
 

Click somewhere in the Form1 window to add the TextBox...

 
 
6.
 

...and again choose TextBox in Toolbox and add another TextBox bellow the first one.

 
 
7.
 

Now we're going to add a Button...

Choose Button in the Toolbox...  

 
 
8.
 

...and click in Form1 to add it.

Add it bellow both of the TextBoxes (see picture).

 
 
9.
 

In the Button properties look for the Text field and enter a new name for your button (see picture).

Duplicate in my case.

 
 
10.
 

Now double click the Button.

 
 
11.
 

A new Tab/Window Form1.vb appears with some code already displayed.

We're going to put some code to trigger the copy of the text entered in first TextBox into the second TextBox.

Click the empty space under the Private Sub function ...


 
 
12.
 

... and enter Dim a As String line.

We just defined a string variable with a name a.


 
 
13.
 

Bellow the variable row you just entered, put this in:

a = TextBox1.Text
TextBox2.Text = a

Basically this two rows copy the text from the first TextBox into another using the so called temporary variable in our case, variable a. The a gets the the value of the TextBox1 and in the next row TextBox2 gets the value of a.



 
 
14.
 

Click Form1.vb [Design] tab, to enter the design view.

 
 
15.
 

Let's make our two text fields a bit wider.

Click it and drag the right edge a bit to the right (see picture)...

Do the same for the second text field as well.

 
 
16.
 

Let's test our little program.

Click the Start Debugging button or press F5.

 
 
17.
 

The Form will now appear as an actual program ready to be tested.

Type something in the first Text Box and click Duplicate.

 
 
18.
 

It works like a charm!

Click here for the lesson on how to save and compile your application so you can run it independently on any supported Windows computer.

If you have any questions or comments regarding the lesson, please don't hesitate to use the Forum.

 
 
 
   
  Please login to post a comment
   
 
 
online learning made for people
Dreevoo.com | CONTRIBUTE | FORUM | INFO