Visual Basic Questions and Answers – Declaring and Using a Structure Variable

«
»

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “Declaring and Using a Structure Variable”.

1. Variables declared using a structure is known as ___________________
a) Variables
b) Auto variables
c) Structure variables
d) Constant variables
View Answer

Answer: c
Explanation: After entering the Structure statement in the Code Editor window, you then can use the structure to declare a variable. Variables declared using a structure are often referred to as structure variables. The syntax for creating a structure variable is shown below:
{Dim | Private} structureVariableName As structureName
advertisement

2. You refer to the structure variable by its ____________
a) Name
b) Data type
c) Dot operator
d) Member name
View Answer

Answer: a
Explanation: In code, you refer to the entire structure variable by its name—in this case, hourly. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

3. You refer to the member variable by preceding its name with the name of the _________________________ in which it is defined.
a) Variable
b) Auto variable
c) Structure variable
d) Constant variable
View Answer

Answer: c
Explanation: In code, you refer to the entire structure variable by its name—in this case, hourly. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

4. Programmers use _________________ when they need to pass a group of related variables.
a) Structure variable
b) Variable
c) Auto variable
d) Constant variable
View Answer

Answer: a
Explanation: Programmers use structure variables when they need to pass a group of related items to a procedure for further processing, because it’s easier to pass one structure variable rather than many individual variables. Programmers also use structure variables to store related items in an array, even when the members have different data types.

5. Programmers use ________________ when they need to store related items in an array, even though the members have different data type.
a) Structure variable
b) Variable
c) Auto variable
d) Constant variable
View Answer

Answer: a
Explanation: Programmers use structure variables when they need to pass a group of related items to a procedure for further processing, because it’s easier to pass one structure variable rather than many individual variables. Programmers also use structure variables to store related items in an array, even when the members have different data types.
advertisement

6. Which statement is used to create a user-defined data type?
a) Declare
b) Define
c) Struct
d) UserType
View Answer

Answer: c
Explanation: Struct is used to create a user-defined data type. It can contain members of different data type. We can access the member by using structName.memberName. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

7. A structure variable named address contains a member variable named strStreet. Which of the following statements assigns the string “Maple” to the member variable?
a) address&strStreet = “Maple”
b) address.strStreet = “Maple”
c) strStreet.address = “Maple”
d) strStreet&address=”Maple”
View Answer

Answer: b
Explanation: We can access the member by using structName.memberName. You refer to a member variable by preceding its name with the name of the structure variable in which it is defined. You use the dot member access operator (a period) to separate the structure variable’s name from the member variable’s name.

8. An array is declared using the statement Dim inventory(4) As Product. Which of the following statements assigns the number 100 to the intQuantity member variable contained in the last array element?
a) inventory.intQuantity(4) = 100
b) inventory(4).Product.intQuantity = 100
c) inventory(3).intQuantity = 100
d) inventory(4).intQuantity=100
View Answer

Answer: c
Explanation: You refer to a member variable in an array element using the syntax arrayName(subscript).memberVariableName. For example, priceList(0).strId refers to the strId member contained in the first element in the priceList array. Likewise, priceList(4).intPrice refers to the intPrice member contained in the last element in the pricelist array.

9. An application uses a structure named Employee. Which of the following statements declares a five-element array of Employee structure variables?
a) Dim workers(4) As Employee
b) Dim workers(5) As Employee
c) Dim workers As Employee(4)
d) Dim workers As Employee(5)
View Answer

Answer: b
Explanation: Rather than using two parallel one-dimensional arrays to store the workers, the procedure will use a one-dimensional array of Employee structure variables. Thus Dim workers(5) As Employee declares a five-element array of Employee structure variable.
advertisement

10. In most applications, the code to define a user-defined data type is entered in the form’s.
a) Declarations section
b) Definition section
c) Load event procedure
d) User-defined section
View Answer

Answer: a
Explanation: you will declare the structure in the form’s Declarations section. A descriptive name for the structure would be ProductInfo. Click the blank line immediately below the Public Class frmMain clause and then press Enter to insert another blank line. Enter the following Structure statement:
Structure ProductInfo
Public strId As String
Public intPrice As Integer
End Structure

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