Visual Basic Questions and Answers – Passing Variables

«
»

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “Passing Variables”.

1. Every variable has both a value and _____________
a) Unique address
b) Value
c) Name
d) Relative address
View Answer

Answer: a
Explanation: Every variable has both a value and a unique address that represents its location in the computer’s internal memory. Visual Basic allows you to pass either a copy of the variable’s value or the variable’s address to the receiving procedure.
advertisement

2. Passing a copy of the variable is referred to as _____________________
a) Pass by value
b) Pass by address
c) Pass by reference
d) Pass by pointer
View Answer

Answer: a
Explanation: Passing a copy of the variable’s value is referred to as passing by value. Passing a variable’s address is referred to as passing by reference. The method you choose—by value or by reference—depends on whether you want the receiving procedure to have access to the variable in memory. In other words, it depends on whether you want to allow the receiving procedure to change the variable’s contents.

3. Passing a variable’s address is referred to as _____________________
a) Pass by value
b) Pass by address
c) Pass by reference
d) Pass by pointer
View Answer

Answer: c
Explanation: Passing a copy of the variable’s value is referred to as passing by value. Passing a variable’s address is referred to as passing by reference. The method you choose—by value or by reference—depend on whether you want the receiving procedure to have access to the variable in memory. In other words, it depends on whether you want to allow the receiving procedure to change the variable’s contents.

4. To pass a variable by value, you include the keyword ________________ before the name of its corresponding parameter.
a) ByVal
b) Val
c) PassVal
d) Pass
View Answer

Answer: a
Explanation: To pass a variable by value, you include the keyword ByVal before the name of its corresponding parameter in the receiving procedure’s parameter list. When you pass a variable by value, the computer passes a copy of the variable’s contents to the receiving procedure. When only a copy of the contents is passed, the receiving procedure is not given access to the variable in memory. Therefore, it cannot change the value stored inside the variable. It is appropriate to pass a variable by value when the receiving procedure needs to know the variable’s contents, but it does not need to change the contents. Unless you specify otherwise, variables in Visual Basic are automatically passed by value.

5. The ___________statement does not indicate whether a variable is passed by value or by reference.
a) Call
b) Parameter
c) Function
d) Declaration
View Answer

Answer: a
Explanation: The Call statement does not indicate whether a variable is being passed by value or by reference. To make that determination, you need to look at the receiving procedure’s header.
advertisement

6. The position of an item in a list box depends on the value stored in the list box’s ____________________
a) Ascending property
b) Descending Property
c) Sorted property
d) Unsorted property
View Answer

Answer: c
Explanation: The position of an item in a list box depends on the value stored in the list box’s Sorted property. When the Sorted property is set to False (the default value), the item is added at the end of the list. When the Sorted property is set to True, the item is sorted along with the existing items and then placed in its proper position in the list. Visual Basic sorts the list box items in dictionary order, which means that numbers are sorted before letters, and a lowercase letter is sorted before its uppercase equivalent.

7. The items in a list box are sorted based on the ___________ characters in each item.
a) Leftmost
b) Rightmost
c) Previous
d) Next
View Answer

Answer: a
Explanation: The items in a list box are sorted based on the leftmost characters in each item. As a result, the items “Personnel”, “Inventory”, and “Payroll” will appear in the following order when the control’s Sorted property is set to True: Inventory, Payroll, Personnel. Likewise, the items 1, 2, 3, and 10 will appear in the following order when the control’s Sorted property is set to True: 1, 10, 2, 3.

8. The ___________ keyword tells the computer to pass the variable’s address rather than its contents.
a) ByRef
b) ByVal
c) ByAdd
d) ByPoint
View Answer

Answer: a
Explanation: You pass a variable by reference when you want the receiving procedure to change the contents of the variable. To pass a variable by reference in Visual Basic, you include the keyword ByRef before the name of its corresponding parameter in the receiving procedure’s header. The ByRef keyword tells the computer to pass the variable’s address rather than its contents.

9. The items listed in the Call statement are referred to as ____________________
a) Arguments
b) Parameters
c) Passers
d) Callers
View Answer

Answer: a
Explanation: The items listed in the Call statement are referred to as arguments; and the items listed in the calling statement are referred to as parameters.
advertisement

10. Which of the following is false?
a) A function can return one or more values to the statement that invoked it
b) A procedure can accept one or more items of data passed to it
c) The parameter List in a procedure header is optional
d) At times, a memory location inside the computer’s internal memory may have more than one name
View Answer

Answer: a
Explanation: A function can return only one value to the statement that invoked it. Since return statement is the last statement of any function.

Sanfoundry Global Education & Learning Series – Visual Basic.

To practice all areas of Visual Basic, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn