5. Sub ProceduresSub Procedures((
]]Accessing Type] Sub Procedure Name (Parameter ListAccessing Type] Sub Procedure Name (Parameter List((
StatementsStatements
End SubEnd Sub
Procedure Name ( [Parameter ListProcedure Name ( [Parameter List[ ([ (
6. 11:(:(
Private Sub Command_ClickPrivate Sub Command_Click( )( )
Dim X, Y, Z As IntegerDim X, Y, Z As Integer
X = 40X = 40
Y = 135Y = 135
Z = 90Z = 90
Max (X, Y, Z)Max (X, Y, Z)
End SubEnd Sub
Private Sub Max (A, B, C, As Integer)Private Sub Max (A, B, C, As Integer)
Dim Answer As IntegerDim Answer As Integer
Answer = AAnswer = A
If B > Answer Then Answer = BIf B > Answer Then Answer = B
If C > Answer Then Answer = CIf C > Answer Then Answer = C
Print "Maximum Value =" ; AnswerPrint "Maximum Value =" ; Answer
End SubEnd Sub
7. Sub FunctionsSub Functions((
•FunctionFunctionSubSubReturn a ValueReturn a ValueTypeType..
•
Private Sub Command – Click ( )Private Sub Command – Click ( )
Dim X, Y, Z, S, P As RealDim X, Y, Z, S, P As Real
X = 2.8X = 2.8
Y = 12.5Y = 12.5
Z = 30.2Z = 30.2
Print "Summation of X,Y and Z =" Sum (X, Y, Z)Print "Summation of X,Y and Z =" Sum (X, Y, Z)
Print "Product of X,Y, and Z = "; Prod (X, Y, Z)Print "Product of X,Y, and Z = "; Prod (X, Y, Z)
End SubEnd Sub
Public Function Sum (A, B, C, As double) As doublePublic Function Sum (A, B, C, As double) As double
Sum = A + B + CSum = A + B + C
End FunctionEnd Function
Public Function Prod (A, B, C, As double) As doublePublic Function Prod (A, B, C, As double) As double
Prod = A * B * CProd = A * B * C
End FunctionEnd Function
15. Call By ValueCall By Value((
Private Sub MainPrivate Sub Main( (( (
Dim A, B As IntegerDim A, B As Integer
A = 12A = 12
B = 10B = 10
Print " Before Calling: A= ";A; "B= "; BPrint " Before Calling: A= ";A; "B= "; B
Call Calculate ( ByVal A, ByVal BCall Calculate ( ByVal A, ByVal B((
Print "After Calling : A = ";A; "B = " ; BPrint "After Calling : A = ";A; "B = " ; B
End SubEnd Sub
Private Sub Calculate (A As Integer, B As Integer)Private Sub Calculate (A As Integer, B As Integer)
Print "Values in Subroutine Before Any Calculations:"Print "Values in Subroutine Before Any Calculations:"
Print "A= " ; A; "B ="; BPrint "A= " ; A; "B ="; B
A = A + B + 8A = A + B + 8
B = B ^ 2 + 20B = B ^ 2 + 20
Print " Values in Subroutine After Calculations:"Print " Values in Subroutine After Calculations:"
Print "A=" ; A; " B=" ; BPrint "A=" ; A; " B=" ; B
End SubEnd Sub
Before Calling: A = 12 B = 10Before Calling: A = 12 B = 10
Values in Subroutine Before Any CalculationValues in Subroutine Before Any Calculation::
A = 12 B = 10A = 12 B = 10
Values in Subroutine After CalculationValues in Subroutine After Calculation::
A = 30 B = 120A = 30 B = 120
17. Private Sub Main ( )Private Sub Main ( )
Dim A, B As IntegerDim A, B As Integer
A = 12A = 12
B = 10B = 10
Print " Before Calling: A= ";A; "B= "; BPrint " Before Calling: A= ";A; "B= "; B
Call Calculate ( ByRef A, ByRef B)Call Calculate ( ByRef A, ByRef B)
Print "After Calling : A = ";A; "B = " ; BPrint "After Calling : A = ";A; "B = " ; B
End SubEnd Sub
Private Sub Calculate (A As Integer, B As IntegerPrivate Sub Calculate (A As Integer, B As Integer((
Print "Values in Subroutine Before Any CalculationsPrint "Values in Subroutine Before Any Calculations:":"
Print "A= " ; A; "B ="; BPrint "A= " ; A; "B ="; B
A = A + B + 8A = A + B + 8
B = B ^ 2 + 20B = B ^ 2 + 20
Print " Values in Subroutine After CalculationsPrint " Values in Subroutine After Calculations:":"
Print "A=" ; A; " B=" ; BPrint "A=" ; A; " B=" ; B
End SubEnd Sub
Before Calling : A = 12 B = 10Before Calling : A = 12 B = 10
Values in Subroutine Before Any CalculationValues in Subroutine Before Any Calculation::
A = 12 B = 10A = 12 B = 10
Values in Subroutine After CalculationValues in Subroutine After Calculation::
A = 30 B = 120A = 30 B = 120
After Calling: A = 30 B = 120After Calling: A = 30 B = 120
19. •OptionalOptionalParametersParameters
a. Private Sub ex1a. Private Sub ex1 ( x As Integer, Optional Y As Integar( x As Integer, Optional Y As Integar(.(.
b. Private Sub ex2b. Private Sub ex2 (Optional A As Integer, Optional B As Integer, Optional C As Integer(Optional A As Integer, Optional B As Integer, Optional C As Integer(.(.
Call ex1(10Call ex1(10((
1010XXYY((
Call ex1(10, 12Call ex1(10, 12((
1010XX1212YY((
e x 2e x 2
Call ex2Call ex2
C, B, AC, B, A((
Call ex2( ,15, 40Call ex2( ,15, 40((
AA1515BB4040CC((
Call ex2 ( , , 40Call ex2 ( , , 40((
AABB4040CC((
20. ::
Private Sub CalculatePrivate Sub Calculate( (( (
Call TestCall Test
Call test(5Call test(5((
Call Test(5,12Call Test(5,12((
Call Test(5,12,3Call Test(5,12,3((
Call Test( ,12Call Test( ,12((
Call Test( , ,3Call Test( , ,3((
End SubEnd Sub
Private Sub TestPrivate Sub Test (Optional A As Integer = 50, Optional B As Integer= 15(Optional A As Integer = 50, Optional B As Integer= 15,,
Optional Z As Integer = 20Optional Z As Integer = 20((
Dim Sum As Integer, Product As IntegerDim Sum As Integer, Product As Integer
Sum = A + B + CSum = A + B + C
Product = A*B*CProduct = A*B*C
Print "A= "; A; "B= " ; B; "C="; CPrint "A= "; A; "B= " ; B; "C="; C
Print "Sum of A, B, and C= "; SumPrint "Sum of A, B, and C= "; Sum
Print " Product of ' A' B and C =" ; ProductPrint " Product of ' A' B and C =" ; Product
End SubEnd Sub
21. Exit Sub and Exit FunctionExit Sub and Exit Function((
•VB6VB6Exit SubExit SubSubSub((End SubEnd Sub.(.(
•Exit FunctionExit FunctionFunctionFunctionEnd FunctionEnd Function.(.(
22. •
•DimDim
Dim A As IntegerDim A As Integer
Dim Sum As Integer, Auerage As RealDim Sum As Integer, Auerage As Real
•Average, Sum, AAverage, Sum, A
End SubEnd SubEnd FunctionEnd Function
23. StaticStaticDimDim
Static Dim X As Integer, Y As RealStatic Dim X As Integer, Y As Real
Static W As StringStatic W As String
•W, Y, XW, Y, XProjectProject
•DefaultDefaultStaticStatic
Private Static Sub Find( )Private Static Sub Find( )
Dim X As Integer, Y As RealDim X As Integer, Y As Real
..
..
End SubEnd Sub
24. Local ScopeLocal Scope:(:(
End SubEnd Sub.(.(
Private ScopePrivate Scope:(:(
Module ScopeModule ScopePrivatePrivateFormFormProjectProject
Public ScopePublic Scope:(:(
PublicPublicProjectProject
26. nn
Private Function RecFact (n As Integer) As LongPrivate Function RecFact (n As Integer) As Long
If n < = 1 ThenIf n < = 1 Then
RecFact = 1RecFact = 1
ElseElse
RectFact = n * RectFact (n – 1)RectFact = n * RectFact (n – 1)
End IfEnd If
End FunctionEnd Function