Visual Basic Tutorial

Visual Basic Tutorial: Creating First Visual Basic Project

Description:

Creating First Visual Basic Project- in this first visual basic tutorial article, I am going to show you how to make a new project, and how to add buttons, labels on the form and then control with a click event in a very simple way


Creating New Project in visual basic Vb.net:

For Creating a new visual basic project simply click on the file menu, in the file menu simply click on new, in the new dropdown menu click on the project or simply press the Ctrl+Shift+N. In the New Project window that opens, a list of Installed Templates appears in the left column. These include templates for programming languages built into Visual Studio, including Visual Basic, Visual C#, Visual C++, Visual F#, and others.

Visual basic project

Select the Visual Basic language and then click on the Windows Forms Application template in the Templates area in the middle column.

Select the Visual Basic language and then click on the Windows Forms Application template in the Templates area in the middle column.

Visual basic project



Now enter the project name Project1 and click on the OK button. The window result is shown in the below Figure.

Visual basic project

This window contains a display form – Form1, in which programmers arrange various components of the graphical user interface or, as they are otherwise called, controls. These are the text boxes for the TextBox, command buttons Buttons, lines of text in the form – Labels that cannot be edited by the user, and other controls. And here we use the most modern, so-called visual programming, which involves simple dragging and dropping into the form of certain elements from the Toolbox panel, where all kinds of controls are located. Thus, they try to minimize the direct writing of the program code.


Designing First Visual Basic Project:

In our first program, we will create a display with a caption, for example, “Programming Digest”. In addition to it, the form will contain a command button labeled “Click me”. Clicking the button will open a dialog box with the message “Hello Programming Digest!”

Now let’s add the named controls to the form. For this, we will need a Toolbox control panel. If at the moment you are not seeing this panel on the screen, you can add it, for example, using the <Ctrl> + <Alt> + <x> key combination or by executing the View | Toolbox. So add Label and Button to the form by double-clicking on these items in the Toolbox.

Visual basic project

Visual basic project


And then arrange them approximately as shown in the below figure.

Visual basic project

Any such object can be created independently, or you can use a ready-made one. In this project, we use ready-made visual objects that you can also just drag and drop from the control panel Toolbox into the form window.

In doing so, we need to know that each object has properties (Properties). For example, the properties of the button are: the name of the button (Name) – in our case Button1, the label on the button (Text) in our Button1, the location of the button (Location) in the X, Y form coordinates, the size of the button (Size), etc. There are many properties, all of them can be see in the Properties panel (see below Figure), which will open if you right-click within the form and select from the context menu the Properties command.

Visual basic project


Let’s get back to our project. For the Label1 object, select the Text property and write next to this field: Programming Digest(instead of the Label1 text) and set font size.

Visual basic project

For the Button1 object, also in the Text property, write: Click me and set font size as per your requirement.

Visual basic project

And change the button name from button1 to BtnClick

Visual basic project

So that objects have properties, we already understood. You should also know that objects are handled by events. An event, for example, is a click on a button, a click within the form, loading (load) the form into RAM when the program starts, etc. Control an event by writing an event procedure in code. To do this, you first need to get an “empty” event handler (i.e., a software write). In our task, the only event we manage is the click of a command button. To get an empty handler for this event, double click on the  Button1  you will see the Form1.vb tab (see below Figure).

Visual basic project

In the Form1.vb tab, we can see that the Visual Basic 12 managing environment has created four lines of code. The reader should not be horrified looking at this still incomprehensible code – gradually everything will become clear. So, in the above figure. shows the program code describing the “empty” handler of the BtnClick event mentioned by us between the lines Private Sub … and End Sub we can write commands to be executed after the user clicks on the command button.

As you can see, we now have two tabs: the tab of the program code Form1.vb and the tab of the visual design of the program (another name for this tab is the form designer) Form1.vb [Design]. You can switch between them with the mouse or by pressing the key combination <Ctrl> + <Tab>, as is customary for switching between tabs in Windows, as well as the <F7> function key.



Visual Basic Vb.net Programming:

Let me remind you that, according to the condition of the task, after clicking on the button, a dialog box should open with the message: “Hello Programming Digest!” To do this, between the two automatically generated lines Private Sub … and End Sub of the event handler we will write:

This entry calls the Show method (program) of the MessageBox object with the text “Hello Programming Digest!” The dot (.) operator tells the system to find the Show method among the methods of the MessageBox object. Well, here I “accidentally,” said that objects, besides properties, also have methods, i.e. programs that process objects.


Thus, we have written a procedure to handle the Click event on Button1. Now press the play button or  <F5> key and check the program’s performance.

Visual basic project

Congratulations, you have written your first program in MS Visual Basic 12!

One Comment

  1. This article is a shining example of what quality journalism should look like. The author’s ability to present complex issues in a way that is both informative and engaging is truly impressive, and their commitment to presenting balanced and unbiased perspectives is admirable. What I appreciate most about this article is its ability to tackle a range of issues with depth and nuance, providing readers with a deep and nuanced understanding of the social and political issues that impact our world.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button