PROGRAMMING WITH VBA - Practice Mode

1) Which scope does the variable declared with dim and remains in the existence only as long as the procedure in which if is declared is running?
Correct Answer: Local scope
2) What will be the output of the following VBA code?
Sub test()
a = 9
Debug.Print Sqr(a)
End sub
Correct Answer: 3
Explanation:

This VBA code defines a subroutine named "test" and within this subroutine, it declares a variable named "a" and assigns it the value of 9. Then it calls the VBA built-in function "Sqr()", which returns the square root of its argument, passing the variable "a" as an argument. Finally, it uses the "Debug.Print" function to print the result of the "Sqr()" function to the debug window.

So the value of the square root of 9 is 3, that's why the output will be "3" Please note that Sqr() is a VBA inbuilt function for finding square root, it does not depend on specific libraries or add-ons and is available in all VBA enabled applications, by default.

3) What will be the output for the following VBA code?Debug.print
DateDiff('yyyy','1/12/2016','31/1/2017')
Correct Answer: 1
4) What will be the output of the following VBA code?
Sub test()
x = 'institue'
Debug.print Format(x,'>')
End sub
Correct Answer: Institute
5) What will be the output of the following VBA code?
Sub test()
Dim S AS string
S = 'wholehearted'
Debug.Print mid(s,6,4)
End sub
Correct Answer: hear