Sub Procedures and Input Boxes in Visual Basic 2010


A sub-procedure is a piece of code in Visual Basic which is used to cover a task. It doesn’t return a value. Only when it is called, its lines are executed and the control is returned back to the calling code. Every Visual Basic program contains at least one subs, the MainSub. Every subs in turn, ends with an End Sub.

By default the subs are Public. It means that they can be accessed anywhere in the project. You can also change its visibility to Private. Once subs are declared Private, it is only accessible in its corresponding form.

Subs can also be defined by User. We call them the user-defined subs.

How to Declare a Sub-Procedure:

The general syntax for declaring a sub is:

Modifiers: specifies the accessibility of the sub in the project. Possible values can be Public, Private, Protected, and etc.

Sub-name: A name you would like to give to your Sub.

Parameters-List: List of the parameters you would like to define in your Sub.

Subs Example:

In the example below; we have created a form which contains a button (Run-Sub). We have further created a User-defined sub [Addition ()] which add two numbers.



Sub Output

Previous Article on Visual Basic 2010

Input Boxes:

An input box is a dialogue box which allows the programmer to request a value from the user. Moreover; an input box displays an OK and CANCEL button. It also contains a title.

Parameters of an Input Box:

Prompt: It is the value which the programmer requests from the user.

Title: It is the title for the Input Box.

Except the first parameter all others are optional. You can leave them empty. We will discuss further about the 3 remaining parameters later.

Input Box Example:

Create a form. Drag and drop a label on your form. Name the label and put its text empty. Double click on the form. Now you can start coding your input box. Don’t forget that you need a variable string to store the value that the user is going to enter in the input box.



Input Box Output 1

Once you enter the value in the input box; click on OK button.

Input Box Output 2

Input Box is very useful in Visual Basic. It prevents the programmer from creating new forms when he wants to get an input from the user.

What happens if you click on CANCEL button?

If the user clicks the CANCEL button; the input box will not pass the user value. In other words; the input box will return a zero-length string.


Input Box Output 3


While working with Input Box, it is necessary to remember that if you do not want to fill all the parameters of the Input Box, you should retain their corresponding commas.

Feel free to post your comments, ask for articles and send us your articles to get published.

Leave a Reply