Modularizing code in procedures
In addition to custom functions, VB allows developers to create custom procedures to perform specific tasks within their programs. Procedures are defined using the Sub
keyword, followed by the name of the procedure, any arguments it takes (if any), and the code that should be executed when the procedure is called. Here’s an example:
Sub dspMsg(msg As String) MsgBox msg End Sub
This procedure takes a string argument, msg, and displays it in a message box using the MsgBox
function. The Sub
keyword indicates that the procedure does not return a value.
To call the procedure, you can use its name and pass in the required arguments:
dspMsg("Hello and welcome!")
In this example, the DisplayMessage
procedure is called with the argument, "Hello and welcome!"
, displayed in a message box.
Custom procedures can be used to encapsulate complex tasks or sequences of operations and called from any part...