26/02/2013

How to create general sub procedure and function in Vb.Net? some example for beginners

In any programming language we code sub procedures and function to avoid repetition of same code or a block of code so in  This post we  covers several important topics: (1) use of menus and context menus in place of and in addition to button controls, (2) writing general sub procedures and functions to modularize your code and make the logic easier to understand, and (3) the use of common dialog boxes – these are controls that are designed to support common tasks such as printing, changing the interface (fonts and colors), and saving files. Function always return value but procedure not.Sometimes a programming module will become quite large, and it makes sense from a logical design perspective to divide the module into two or more separate procedures.
·  You can store the code to a separate procedure, and then call the code from multiple button and menu control click events. 
·  You can also develop a procedure that you "reuse" by calling it from either a context menu or regular menu or button that is clicked.
·  This is a third way to avoid duplicating (copying) code in a program, along with the PerformClick method and the alteration of the Handles clause.

There are two types of general procedures
·   Sub procedures that perform actions, but are not associated with any specific event such as a click event.  One use of sub procedures is to set property values for a series of objects.  Another use is to perform an action such as shutting down an application by use of a standard shutdown process.
·   Function procedures (also called user-defined functions [UDFs] or simply functions) that perform actions, are not associated with any specific event, and that also return a value.   You use functions to calculate values that are returned to the calling procedure.

:

No comments:

Post a Comment

What & How