Local Variables
Dim sum As Integer
Static Variables
preserves value even when a procedure ends. Static intPermanent As Integer all variables in a procedure static Static Function RunningTotal ( )
Module Levele Variables
available to all the procedures in the module Private LoginTime As Date Public variables in BAS modules are global variables
Public vs Local Variables
References to the name R within the procedure would access the local variable and references to R outside the procedure would access the public variable.
Sub Procedures
[Private | Public] [Static] Sub Procedurename [( arglist)] [ statements] End Sub
Event Procedures
write common statements in a separate procedure (general procedure) and then call them in the event procedure.
Function Procedures
Function Hypotenuse (A As Double, B As Double) As Double Hypotenuse = sqr (A^2 + B^2) End Function
Property Procedures
?
If...Then selection structure
If <condition> Then statement End If
If...Then...Else/ Nested If...Then...Else Select...Case
average = txtAverage.Text Select Case average Case 100 To 75 txtGrade.Text ="A" Case 74 To 65 txtGrade.Text ="B" Case 64 To 55 txtGrade.Text ="C" Case 54 To 45 txtGrade.Text ="S" Case 44 To 0 txtGrade.Text ="F" Case Else
MsgBox "Invalid average marks" End Select
Do While... Loop
Dim number As Integer number = 1 Do While number <= 100 number = number + 1 Loop
While... Wend
Dim number As Integer number = 1 While number <=100 number = number + 1 Wend
Do...Loop While
Dim number As Long number = 0 Do number = number + 1 Loop While number < 201
Do Until...Loop
Dim number As Long number=0 Do Until number > 1000 number = number + 1 Print number Loop
The For...Next
For x = 1 To 50 Step 2 Print x Next
Exit For
Dim x As Integer Do While x < 10 Print x x=x+1 If x = 5 Then Print "The program is exited at x=5" Exit Do End If Loop
With...End With
Function Year ( ) Month ( ) Day ( ) WeekDay ( ) Hour ( ) Minute ( ) Second ( )
Extracted Portion Year (Now) Month (Now) Day (Now) WeekDay (Now) Hour (Now) Minute (Now) Second (Now)
The calculation and conversion functions related to date and time functions are listed below. Function DateAdd ( ) DateDiff ( ) DatePart ( ) DateValue ( ) TimeValue ( ) DateSerial ( ) Description Returns a date to which a specific interval has been added Returns a Long data type value specifying the interval between the two values Returns an Integer containing the specified part of a given date Converts a string to a Date Converts a string to a time Returns a date for specified year, month and day
Function DateAdd ( ) DateDiff ( )
Description Returns a date to which a specific interval has been added Returns a Long data type value specifying the interval between the two values Returns an Integer containing the specified part of a given date Converts a string to a Date Converts a string to a time Returns a date for specified year, month and day
DatePart ( ) DateValue ( ) TimeValue ( ) DateSerial ( )
DateDiff Function
The DateDiff function returns the intervals between two dates in terms of years, months or days. The syntax for this is given below.
DateDiff (interval, date1, date2[, firstdayofweek[, firstweekofyear]])
Format Function
The format function accepts a numeric value and converts it to a string in the format specified by the format argument. The syntax for this is given below.
Format (expression[, format[, firstdayofweek[, firstweekofyear]]])
The Format function syntax has these parts:
Part Expression format firstdayofweek Description Required any valid expression Optional. A valid named or user-defined format expression. Optional. A contant that specifies the first day of the week.
firstweekofyear
Optional. A contant that specifies the first week of the year