Page 187 - Open Soource Technologies 304.indd
P. 187
Unit 7: Arrays in Visual Basic
7.7 Review Questions
1. Write code to declare an array with upper bound 10 and place the names of the five Great
Lakes into the first five elements. Use one or two lines of code.
2. Suppose the Integer array quantities() has been declared with an upper bound of 100 and
data have been placed into several elements of the array. Write one line of code that will
restore the values of all the elements to their default value of 0.
3. Write code to declare an array of size 20 and place the names Jerry, George, Elaine, and
Kramer into the first four elements. Use one or two lines of code.
4. Declare the string array marx() with upper bound 3 so that the array is visible to all parts
of the program. Assign the four values Chico, Harpo, Groucho, and Zeppo to the array
before any buttons are pressed.
5. Declare the string array stooges() to have size 3 so that the array is local to the event
procedure btnStooges_Click. Assign the three values Moe, Larry, and Curly to the array
as soon as the button is clicked.
6. The arrays a() and b() have been declared to have upper bound 4, and values have been
assigned to a(0) through a(4). Store these values in array b() in reverse order.
7. Write a program that asks the user for a month by number and then displays the name
of that month. For instance, if the user inputs 2, the program should display February.
Hint: Create an array of 12 strings, one for each month of the year.
8. Assuming that the array is in ascending order, determine how many numbers appear more
than once in the array?
9. Write a procedure to place all the 40 numbers from arrays a() and b() into c() so that c()
is also in ascending order. The array c() could contain duplications.
10. Explain about arrays.
11. If you intend to dynamically create a TextBox control from a control array at runtime, what
two things must you do at design time for this to work?
Answers for Self Assessment Questions
1. (d) 2. (b) 3. (a) 4. (c)
5. Rows and columns.
7.8 Further Readings
G. Cornell , “Visual Basic 6”, Tata McGraw-Hill, 1998.
Null Dale, Michael Mc Millan, ”Visual Basic .Net.”
http://microsoft.com/mspress/findabook/list/title.aspx
LOVELY PROFESSIONAL UNIVERSITY 181