CIS 56 INTRODUCTION TO VISUAL BASIC

SPRING SEMESTER 2003

QUIZ #1

 

DIRECTIVES:

 

PART I:

As explicitly as possible, answer any 20 of the following 25 questions. (4 pts ea.)

 

1)                  Explain the difference between a local variable and a module variable along with the concept of scope.

 

2)                  Explain the difference between the Format Currency function and the Format Number function and give an example of each, describing each in detail.

 

3)                  Name the five windows in the Visual Basic environment and explain the function of each. Note => Visual Basic environment.

 

4)                  Name and describe the two ways in which you can select multiple controls, deselect those controls and move those controls.

 

5)                  Explain the concept of concatenation, code an example and demonstrate what the result would look like.

 

6)                  When a line of code gets to be too long for one line of typing, you can do something about it. What would you do/use, what are its restrictions, and give an example.

 

7)                  Explain the difference between named and intrinsic constants, give an example of each and explain how a string literal can be assigned to a constant to include double quotes as part of the string. Be explicit.

 

8)                  Explain the difference between a method and an event.

 

9)                  Explain the difference between an object and a property.

 

10)              What is the hierarchy of arithmetic operations and what would the answer be to each of the following?

 

        2 ^ 3 * 4 + 7 8

        2 ^ ((2*4) -2)

        (4 + 12 ( 6*3) ) / 2

        (21 / 7 ) + 2 ^ 3

        2 * (( 8 + ( 6 * 3) 8 / 2) * 2)

 

11)              What is Option Explicit? What is its function and, while not wrong to exclude it from a program, explain what possible consequences/problems could develop by excluding it. Site an example, if you like.

 

12)              Other than Variant, what are 7 other types of variables you can declare? When would you use each of these types, and why over all the other types you listed, is the Variant type the one you should use only when you need to?

 

13)              Explain the difference between an option button control and a check box control. When would you use the option button as opposed to the check box and give an example of how you would run a test on each to see if they were clicked or not.

 

14)              I enter a value in a text box called txtNewAmt. Before I do any calculations with it, I want to be sure that it contains numeric data. Code the If statement, using the proper function to test for its validity. If it is numeric, code the statement, using the proper function to assign it to a declared variable, declared in general declarations, called mNewAmtWrk, which was declared to hold numeric data. Also, code the opposing action to be taken if it is not numeric, causing notification to the user and resetting the text box.

 

15)              What is the name of the area in which Option Explicit is located?

 

16)              When you have the code window displayed and you are typing in your program code, there are two drop-down lists at the top of the window you can use. What are their respective names?

 

17)              The code statement, Print The Wonderful Wizard of Oz, coded in a command buttons click event would do what, on what and exactly where and why? What would happen on each successive press of that button until a clear method is executed and, when the clear method is executed, what would happen when the print command button is again pressed?

 

18)              If I want a form to display without any borders on it at all, what property would I have to set and to what would I have to set it? Also, if instead, I dont want any min, max or close buttons to show on my form at run-time, what control would I set and to what would I have to set it. If at run-time I want to prevent the user from moving the form around the screen, what control would I set and to what would I set it?

 

19)              Name two ways by which I can display my code window at design time.

 

20)              Explain the difference between a run-time error, a syntax error and a logic error.

 

21)              What are the prefixes used in naming the following objects; a form, a command button, a text box, a label, an option button, a frame? What are the rules governing the naming of objects? What do we mean by an objects naming convention and give at least three examples.

 

22)              Is the following code valid? If not, explain what is wrong with it and correct it. BE EXPLICIT Assume the variable mAgeWrk is declared as type integer. Ignore the bullets, the dots that precede the code, they arent part of the code.

 

        If mAgeWrk > = 65 Then

lblRankStat.Caption = Ready for retirement

Else

lblRankStat.Caption = Keep working!

End If

 

23)              Is the following code valid? If not, explain what is wrong and correct it.

        Dim mScoreWrk As Single

 

If mScoreWrk > 89 And <= 100 Then

mLetterGrade = A

ElseIf mScore >= 80 And mScore < 90 Then

mLetterGrade = B

Else

mLetterGrade = C

End If

End If

 

24)              Is the following code valid? If not, explain what is wrong and correct it.

        Dim mNewNumWrk As Integer

 

If IsNumeric (txtNewNumIn.Text) Then

mNewNumWrk = Val(txtNewNumIn.Text)

Else

MsgBox (You must enter a numeric value.)

txtNewNumWrk.SetFocus

End If

 

25)              In design time, how can I keep myself from inadvertently moving controls around on the form while Im still designing and would setting this feature keep me from adding other controls?

 

PART II:

Write the IF statement for any 2 of the following 4 conditionals. (5pts. ea.) WARNING: Remember to design ifs neatly. A messy if will cause the response to be wrong, even if the code is correct.

 

Realism is not the point of this exercise. The issue here is constructing IF statements. Disregard whether the scenarios make sense or not.

 

I. There is a computer room wherein a company has its mainframe system and server cabinets. Access to this area is limited to certain personnel. These personnel members are: Operators, Programmers, Technicians and IT managers. To gain access to the room a key pad, like a calculator, is mounted outside the door and a person wishing to gain admittance must key in his/her unique ID number and then press enter.

Each code is comprised of 7 numbers and each type of personnels id is within a certain range of those numbers.

 

Operator ids range from 1000000 to1999999

Programmers from 2000000 to 2999999

Technicians from 3000000 to 3999999

Managers from 9000000 to 9999999

 

Any entry outside of those ranges renders a NO ADMITTANCE message.

(In reality, the actual id would be checked but were not concerned with that at this time.)

 

When the id is within a certain range, a message should come up stating that persons position followed by the word ADMITTED.

Example OPERATOR ADMITTED

Write the IF to make this happen. Include all actions in the ifs results.

 

II. A publishing house pays an author royalties based on the number of books sold.

The royalty is a sliding scale based on the number of books sold. Hence:

 

        BOOKS SOLD ROYALTY RATE %

        5000 or less 7

        5001 10,000 9

        10,001 20,000 17

        over 20,000 25

 

This is the calculation for the NET SALES:

CurNetSales = intQtySold * CurNetCost

 

The royalty is calculated by multiplying the royalty rate by the net sales.

 

Write the if statement to determine the royalty and include, in the action to be taken depending on the condition, the calculation you would use now that you have the netsales.

 

III. A bookstore carries two types of books, new and used.

They have five categories of books in these two types.

        Humorous

        Mysteries

        Autobiographies

        Horror

        Religions

 

Humorous and Horror books sell for $5.00 each when used and $10.00 when new.

Autobiographies and Mysteries sell for $7.50 each when used and $12.25 when new.

Religious books sell for $3.00 each when used and $4.75 when new.

Write an if statement to assign to a price variable, which you name, the price based on the type and category of the book.

 

IV. The Golden Girls Blanche Deveraux, Dorothy Zbornack, Rose Nilund and Sophia Petrillo all love chocolate cheesecake and they all love cherry cheesecake. They do, however, have preferences as to what they have with the cheesecake

When Blanche has chocolate cheesecake she likes chocolate ice cream to go with it. When she has cherry cheesecake, she prefers just a cup of coffee.

When Dorothy has chocolate cheesecake she likes vanilla ice cream. With cherry cheesecake she prefers a cup of tea.

When Rose has chocolate cheesecake she likes a glass of milk while with cherry cheesecake she prefers vanilla ice cream.

Sophia likes coffee with chocolate cheesecake and tea with cherry cheesecake.

 

You have a variable called strCondiment.

Write the if statement to assign the preferred condiment to this variable, based on the cheesecake type, and the person having it.

Note: you have two types of cheesecake and 4 people.

 

PART III: NO CHOICE HERE!

You must write the if statement for the following (10pts.)

 

A collectibles record store sells old 45 and 33 vinyl records.

The records are separated into two-year groups, those dating before 1960 and those dating from 1960 on.

Within these two groups, they are again separated into two condition ratings, good and mint conditions.

45s that date before 1960 and are in mint condition, sell for $10.00 each. Those that are rated as good condition sell for $8.75 each.

Those that date after 1959 and are in mint condition, sell for $8.00 each while those in good condition, sell for $7.75 each.

33s that date before 1960 and are in mint condition, sell for $30.00 each while those in good condition, sell for $25.00.

Those that date after 1959 and are in mint condition, sell for $28.00 each while those in good condition, sell for $20.00.

Write the if statement for this problem including the calculations in the conditional results. You also name and include any and all variables you will need.