A sub procedure is an assignment that is carried but does not give back a result. To create a sub procedure, start with the Sub keyword followed by a name (like everything else, a procedure must have a name). The name of a procedure is always followed by parentheses. At the end of the sub procedure, you must type End Sub. Therefore, the primary formula to create a sub procedure is:
Sub ProcedureName()
End Sub
The name of a procedure should follow the same rules we learned to name the variables. In addition:
If the procedure performs an action that can be represented with a verb, you can use that verb to name it. Here are examples: show, display To make the name of a procedure stand, you should start it in uppercase. Examples are Show, Play, Dispose, Close. You should use explicit names that identify the purpose of the procedure. If a procedure would be used as a result of another procedure or a control's event, reflect it on the name of the sub procedure. Examples would be: afterupdate, longbefore.
If the name of a procedure is a combination of words, you should start each word in uppercase. An example is AfterUpdate
The section between the Sub and the End Sub lines is referred to as the body of the procedure. Here is an example:
Sub CreateCustomer()
End Sub
In the body of the procedure, you carry the assignment of the procedure. It is also said that you define the procedure or you implement the procedure.
One of the actions you can in the body of a procedure consists of declaring a variable. There is no restriction on the type of variable you can declare in a procedure. Here is an example:
Sub CreateCustomer()
Dim strFullName As String
End Sub
In the same way, you can declare as many variables as you need inside of a procedure. The actions you perform inside of a procedure depend on what you are trying to accomplish. For example, a procedure can simply be used to create a string. The above procedure can be changed as follows:
Sub CreateCustomer()
Dim strFullName As String
strFullName = "Chidambaram palaniappan"
End Sub
No comments:
Post a Comment