28
100 points Open book, open notes True/false, multiple choice, fill-in, short answer

Cis160 Final Review

Embed Size (px)

Citation preview

Page 1: Cis160 Final Review

100 points Open book, open notes True/false, multiple choice, fill-in, short

answer

Page 2: Cis160 Final Review

Variable Memory locations that hold data that can be

changed during project execution Example: customer’s name

Named Constant Memory locations that hold data that cannot be

changed during project execution Example: sales tax rate

3-2

Page 3: Cis160 Final Review

In Visual Basic when you declare a Variable or Named Constant An area of memory is reserved A name is assigned called an Identifier

Use Declaration Statements to create Variables and Constants Assign name and data type Not executable unless a value is assigned on

same line

3-3

Page 4: Cis160 Final Review

Must follow Visual Basic Naming Rules Cannot use reserved words or keywords that Basic

has assigned a meaning such as print, name, and value

Must begin with a letter and no spaces or periods Should follow Naming Conventions

Names should be meaningful Include class (data type) of variable (intQuota or

Quota_Integer) Use mixed case for variables and uppercase for

constants

3-4

Page 5: Cis160 Final Review

Visibility of a variable is its scope Where is that identifier valid?

Scope may be Namespace: throughout project Module: within current form/class Local: within a procedure Block: within a portion of a procedure

Lifetime of a variable is the period of time the variable exists

3-5

Page 6: Cis160 Final Review

Use static to declare local and block level variables that need to retain their value Variable will not be initialized next time procedure

runs, and will have last value assigned If the variable is used in multiple procedures,

declare it at the module level with private

6-6

Page 7: Cis160 Final Review

Use Parse methods to convert a string to its numeric value before it’s used in a calculation

Each numeric data type class has a Parse method Parse method returns a value that can be used in

calculations Parse method fails if user enters nonnumeric

data, leaves data blank, or entry exceeds data type size

3-7

Page 8: Cis160 Final Review

Enclose statements that might cause a run-time error within Try/Catch block If an exception occurs while statements in the

Try block are executing, code execution is moved to the Catch Block

If a Finally statement is included, the code in that section executes last, whether or not an exception occurred

3-8

Page 9: Cis160 Final Review

This OOP feature allows the Messagebox Show method to act differently for different arguments Each argument list is called a signature: the Show

method has multiple signatures Supplied arguments must exactly match one

of the signatures provided by the method

3-9

Page 10: Cis160 Final Review

Used to make decisions If true, only the Then clause is executed, if

false, only Else clause, if present, is executed Block If…Then…Else must always conclude

with End If Then must be on same line as If or ElseIf End If and Else must appear alone on a line

4-10

Page 11: Cis160 Final Review

Test in an If statement is typically based on a condition

Six relational operators are used for comparison of numbers, dates, and text An equal sign is used to test for equality

Strings can be compared using ANSI value of each character CIS is less than CNA MATH is less than MATH&

4-11

Page 12: Cis160 Final Review

Compound conditions can combine multiple logical conditions And describes conditions where both tests are true Or describes conditions where either or both tests

are true When both And and Or are evaluated And is

evaluated before the Or Use parenthesis to change the order of

evaluation

4-12

Page 13: Cis160 Final Review

Check to see if valid values were entered or available

Can check for a range of values (often called “reasonableness”) If Integer.Parse(scoreTextBox.Text) >= 0 Then

‘ Code to perform calculations…. Check for a required field (not blank)

If studentIDTextBox.Text <> "" Then ...

4-13

Page 14: Cis160 Final Review

Use Select Case to test one value for different matches (“cases”) Usually simpler and clearer than nested If No limit to number of statements that

follow a Case statement When using a relational operator must use

the word Is Use the word “To” to indicate a range with

two endpoints

4-14

Page 15: Cis160 Final Review

Add object/event combinations to the Handles clause at the top of an event procedure Allows the procedure to be associated with

different events or other controls Sender argument identifies which object had

the event happen Cast (convert) sender to a specific object type using

the CType function

4-15

Page 16: Cis160 Final Review

Calling an event procedure allows reuse of code [Call] ProcedureName (arguments)

Keyword Call is optional and rarely used Examples

Call clearButton_Click (sender, e)--OR-- clearButton_Click (sender, e)

4-16

Page 17: Cis160 Final Review

Breakpoints allow you to follow the execution of your code while program is running

Can hover the cursor over a variable or property to see the current value in the current procedure

Can execute each line, skip procedures

Can use Console.Writeline to output values to track code execution

Variables and property values can be seen in different windows (autos, locals) while code is executing

5-17

Page 18: Cis160 Final Review

A general procedure is reusable code which can be called from multiple procedures

Useful for breaking down large sections of code into smaller units

Two types Sub Procedure performs actions Function Procedure performs actions AND returns

a value (the return value)

Page 19: Cis160 Final Review

If a procedure includes an argument, any call to the procedure must supply a value for the argument

Number of arguments, sequence and data type must match

Arguments are passed one of two ways: ByVal – Sends a copy of the argument’s value, original

cannot be altered ByRef - Sends a reference to the memory location where the

original is stored and the procedure may change the argument’s original value

If not specified, arguments are passed by value

5-19

Page 20: Cis160 Final Review

Show method displays a form as modeless - means that both forms are open and the user can move from one form to the other

ShowDialog method displays a new form as modal - the user must close the form in order to return to the original form No other program code can execute until the user

responds to and hides or closes the modal form

6-20

Page 21: Cis160 Final Review

Provide the user with a list of choices to select from

Various styles of display, choose based on Space available Need to select from an existing list Need to add to a list

Listboxes and comboboxes share most of the same properties and operate in a similar way Combo box control has a DropDown Style property Combo box allows text entry

Page 22: Cis160 Final Review

List of items in a ListBox or ComboBox is a collection Collection is group of like objects Items referenced by number (zero-based)

VB Collections are objects that have properties and methods that allow Adding items Removing items Referring to an individual element/member Counting items

Page 23: Cis160 Final Review

Index number of currently selected item is stored in the SelectedIndex property Property is zero-based

If no list item is selected, SelectedIndex property is negative 1 (-1)

Use to select an item in list or deselect all items

Page 24: Cis160 Final Review

A loop repeats a series of instructions An iteration is a single execution of the

statement(s) in the loop Used when the exact number of iterations is

unknown A Do/Loop terminates based on condition

change Execution of the loop continues while a condition

is True or until a condition is True The condition can be placed at the top or the

bottom of the loop

Page 25: Cis160 Final Review

Pretest: test before enter loop loop may never be executed since test executes

BEFORE entering loopDo While … Loop Do Until … Loop

Posttest: test at end of loop loop will always be executed at least once

Do … Loop While Do … Loop Until

Page 26: Cis160 Final Review

Used to repeat statements in a loop a specific number of times

Uses a numeric counter variable called Counter or Loop Index Counter is incremented at the bottom of the loop

on each iteration Start value sets initial value for counter End value sets final value for counter Step value can be included to specify the

incrementing amount Step can be a negative number

Page 27: Cis160 Final Review

Used to repeat statements for each member of a group

A reference variable is used to “point” to each item Must be the data type of each item in group

Page 28: Cis160 Final Review

In some situations you may need to exit the loop prematurely

Use the Exit For or Exit Do statement inside the loop structure Generally used within an If statement (something

must be evaluated to determine whether or not to exit the loop)