Changes

Jump to: navigation, search

Visual Basic Modules and Procedures

407 bytes added, 17:44, 31 July 2007
Defining Visual Basic Subroutines
The ''Public'' keyword indicates that this subroutine is accessible from Visual Basic code residing in other modules. The ''Sub'' keyword indicates that this is a Subroutine (as opposed to a Function) and as such, does not return a value on completion. Finally, the name of the Subroutine is provided. The parentheses are used to hold any parameters which may be passed through to the Subroutine when it is called. The ''End Sub'' code marks the end of the Subroutine. The Visual Basic code that constitutes the Subroutine is placed after the Subroutine declaration and the ''End Sub''.
 
We can write code in the Subroutine to display a message window as follows:
 
<pre>
Public Sub DisplayResult()
 
MessageBox.Show("Test message")
 
End Sub
</pre>
 
Next, Clcik event procedure of the button in our form needs to call the ''DisplayResult()'' Subroutine. Double click on the button in the form to display the event procedure code and add the call to ''DisplayResult()'' as follows:
 
<pre>
== Defining Visual Basic Functions ==

Navigation menu