• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » VB » Menus Procedure and Sub Function

Subroutines and Functions

By Dinesh Thakur

The code you write won’t be a monolithic listing. It will be made up of small segments called procedures and you will work on one procedure at a time. This is called modularized approach of programming.

 

It permeates the Visual Basic language even the longest applications are written by breaking them into small, well defined tasks. Each task is performed by a separate procedure that is written and tested separately from the others. Procedures are useful for implementing repeated tasks.

The two types of procedures are subroutines and functions—the building blocks of your application.

Subroutines : A subroutine is a block of statements that carries out a well-defined task. The subroutine begins with Sub and name of subroutine and its execution stops when EndSub statement is reached, and control returns to the calling program. It is possible to exit a Subroutine prematurely with the Exit statement.

 

Functions : A function is similar to a subroutine, but a function returns a result. Subroutines perform a task and don’t report anything to the calling program; functions commonly carry out calculations and report the result. The statements that make up a function are placed in a pair of Function/End Function statements. Because the function must report the result to the calling program, it must have a return type.

 

Give the Steps Required to Convert a Project into an .exe File

By Dinesh Thakur

You can create .exe file of your project which a executable file. In windows after clicking on the .exe file project starts running. The simple steps for creating .exe file are as follows:

 

1. After completing project save it.

 

2. Then click on file menu.

 

3. In file menu there is an sub menu ‘Make Project’.

 

4. After clicking on Make Project sub menu it will open a save dialog box to locate the path where .exe file will be created.  Select the location and click on Ok then your project will be converted into .exe file at specified location.

 

Difference Between ByRef and ByVal. When would each be used

By Dinesh Thakur

When you pass a value to procedure you may pass it ByVal of ByRef

The ByVal sends a copy of the argument’s value to the procedure cannot alter the original value. ByRef sends a reference indicating where the value is stored in memory, allowing the called procedure to actually change the argument’s original value.  

 

You can specify how you want to pass the argument by using the ByVal or ByRef keyword before the arguments. Arguments are passed by reference by default.

What is return value? How it can be used

By Dinesh Thakur

While writing a Function procedure you must set up a return value. This return value is placed in the a variable that Visual Basic names the with the procedure name as function name.

 

You can also specify the data type of return value by adding as clause after the function name. If return type of Procedure is Currency the procedure should be named as curCommission()

 

The return value can be used as follows:

 

Private Function curCommission(ByVal curSalesAmount as Currency) as Currency

 

‘Calculate the sales commission

If curSalesAmount < 1000 Then

curCommission = 0

Else

curCommission = 1.5 * curSalesAmount

End If

End Function

 

Difference Between Sub Procedure and Function Procedure

By Dinesh Thakur


Sub Procedure

Function Procedures

 

Sub Procedure is procedure that performs some action.

Function Procedure also perform some action but also returns some value to point from which it was called

 

Syntax for Sub Procedure is as follows:

Private Sub <procedure name>

‘ Actions to performed

End Sub

Syntax for Function Procedure is as follows:

Private Function Commission()

‘ Action to performed

Commission = <value that to be return>

End Function

 

Example:

Form_Load()

Example:

Val(), FormatPercentage()

What does the common dialog box means? Explain types of common dialog boxes

By Dinesh Thakur

1. You can use set of predefined standard dialog boxes in your projects for such tasks as specifying colors and fonts, printing, opening and saving. The common dialog boxes control, which is a custom control, allows your project to use the dialog boxes that are  provided as a part of the Windows environment.

2. To use the common dialog control, you first place a control, and its location doesn’t matter, you can not change size of the control, since it will be invisible when your program will run.

3. In code when you wish to display one of the standard dialog boxes, you refer the properties and methods of the control.

4. You don’t need more than one dialog control on your form.

In Visual Basic common dialog box provides commonly used dialog boxes as given below:

1. Color Dialog Box:

Visual Basic common dialog box provides Color dialog box which can be used for user to select color from the common dialog box. You can assign the values selected by user to controls in your project. This dialog box can be used by writing a code as follows:

dlgCommon.ShowColor

2. Font Dialog Box:

Font Dialog Box allows user to select his custom font setting like, font name, font size, font color, font style, strike through etc. To display the font dialog on screen use ShowFont method of the common dialog object.

But before using the ShowFont method you first initiate the flag property for font that is cdlScreenFont.

3. Save Dialog Box:

Visual Basic even provides save file dialog box which displays a save file dialog box to get the path for file to save.

What is Separator Bar and How it is Created

By Dinesh Thakur

1. When you create menus in the menu bar, you should group the commands according to their purpose. You can create a separator bar in a menu, which draws a bar across the entire menu.

 

2. To define a separator bar, type a single hyphen(-) for the caption and give it a name. Even though you can never refer to separator bar in code and it does not have click event, you must still give it a unique name. Call your separator bar mnuSep1.

 

Difference Between Menus and Submenus

By Dinesh Thakur

1. Menus:

 

a. Menus consist of a menu bar with menu names, each of which drops down to display a list of menu commands.

b. You can use menu commands in place of or addition to command buttons to active procedures.

c. Menu commands are actually controls; they have properties and events. Each event has name property and click event, similar to action command buttons.

 

2. Sub menus:

 

d. The drop down list of commands below a menu name is called a menu. When a command on the menu has another list of commands that pops up, the new list is called submenu.

e. The filled triangle to the right of the command indicates the a menu command has a sub menu.

 

Primary Sidebar

Visual Basic Tutorial

Visual Basic Tutorial

  • VB - File Types Purpose
  • VB - Events
  • VB - Ole
  • VB - Controls Properties
  • VB - Project Steps
  • VB - Pretest Vs Posttest
  • VB - IDE
  • VB - Record Set
  • VB - Common Dialog Box
  • VB - Val Function
  • VB - Sub Vs Function Procedure
  • VB - Terms
  • VB - User Interface Elements
  • VB - Objects and Modules
  • VB - Variable’s Scope
  • VB - Message Box
  • VB - Data Vs Data-bound Control
  • VB - Branching Statements
  • VB - Do/Loop and For-Next Loop
  • VB - Grid Control
  • VB - Error Types
  • VB - Looping Constructs
  • VB - Relational Vs Logical Operator
  • VB - Control Purpose

Other Links

  • Visual Basic - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW