PROGRAMMING WITH VBA - Practice Mode

1) How many levels of variable scope available in VBA?
Correct Answer: 4
2) What will be the output of the following VBA code?
Debug.printformat(#1/1/2017#,'yyyy/mm/dd')
Correct Answer: 01-01-2017
Explanation:

The output of the following VBA code will be "2017/01/01". The "Debug.print" statement is used to print the result of the format function to the Immediate Window. The format function takes two arguments: the first one is a date expression, in this case it is the date "#1/1/2017#" which represent January 1, 2017. The second argument is the "format string" which is "yyyy/mm/dd", that means year/month/day in 4 digits, 2 digits and 2 digits respectively.

This code will format the date in the format of year/month/day and return it as a string. The year is represented by 4 digits, month by 2 digits and day by 2 digits, as mentioned in the format string. The date 1/1/2017 becomes 2017/01/01 using the format specified.

3) Which function returns true if the expression is a valid date, otherwise it returns false in VBA?
Correct Answer: IsDate()
4) What is the full form of UDF in VBA?
Correct Answer: User Defined Functions
5) Which function returns the day of the month (number from 1 to 31) given date value in VBA?
Correct Answer: Day()