cis-166 midterm
DESCRIPTION
review materials for cis-166 first testTRANSCRIPT
Midterm ReviewMidterm ReviewCIS-166
ObjectsObjectsClasses provide a templateProperties define the
characteristics and behaviors of an object
Methods are procedures that come with an object – actions it already knows how to do
Variables & ConstantsVariables & ConstantsMemory location for storing data
◦Variable value can change◦Constant value doesn’t change
Different types of data◦Tailor data type to ensure get good
data and maximize use of memory Default data type is object
Variable UseVariable UseOption Explicit makes sure that
variables are declared (defined)Create using Dim or PublicVariables initialized when created
(setting beginning value)
Scoping variablesScoping variablesWithin a blockWithin a procedureForm levelApplication level
EnumeratorsEnumeratorsEnumerators are a way to
manage related constants◦Messagebox buttons◦Type of transaction
Value of a member must be an integer◦Value defaults to 0 for 1st, 1 + prior
value for each additional member
Converting ValuesConverting ValuesConvert classData type – Parse/TryParseCTypeRole of Option Strict
OperatorsOperatorsMathematical
◦Precedence matters!◦^ ; - ; *, / ; \ ; Mod ; +, -
Relational◦< ; <= ; = ; >= ; >
Logical◦Precedence matters!◦Not; And ; Or
If … ThenIf … ThenIf something is true, execute
following commandsCan test for more than one
condition◦Else◦ElseIf
Nested If … Then‘Is’ functions help testing
Case StructureCase StructureBest alternative for testing a
single variable or expression for multiple values
Any decisions coded with nested If statements can also be coded using Case structure
Case Structure is typically simpler, cleaner, more efficient than an If … Then
ProceduresProceduresSubroutine: procedures that
don’t return somethingFunction: procedures that send
back some dataProperties: procedures that
store, return, or both; accept a single argument
Arguments are means to provide data to a procedure
Event ProceduresEvent ProceduresConnect an action with
instructions using HandlesRoles of sender and event
◦What object◦Which event
Sharing an Event Sharing an Event ProcedureProcedureIf the code for multiple controls is similar,
rather than writing separate code for each, the controls can share an event procedure
Use the Handles Clause at the top of the event procedure to enable the code in a single event to be used for multiple controls
Can evaluate the sender to determine the object which triggered the event
Different events have different data types (i.e. form closing is different than click)
Types of List ControlsTypes of List ControlsListBox: Simple List Box with or
without scroll barsComboBox
◦List may allow for user to add new items
◦List may "drop down" to display items in list
◦Combines characteristics of a TextBox with a ListBox
Items CollectionItems Collection
List of items in a ListBox or ComboBox is a collection
Collections are objects that have properties and methods that allow you to◦Add items◦Remove items◦Refer to individual items◦Count items
Index PropertyIndex Property
Zero based value used to reference individual items in the collection
Position of an item in the list◦ 1st item Index = 0 (1-1=0)◦ 2nd item Index = 1 (2-1=1)◦ 3rd item Index = 2 (3-1=2)
LoopsLoopsRepeating a series of instructionsEach repetition is called an
iterationTypes of Loops
◦Do: Use when the number of iterations is unknown
◦For Next: Use when the number of iterations known
Do LoopsDo LoopsEnds based on a condition you
specify, either◦Loop While a condition is True◦Loop Until a condition becomes True
Condition can be located at◦Top of Loop, Pretest◦Bottom of Loop, Posttest
For Next LoopsFor Next Loops
Use when you know the number of iterations
Uses a numeric counter variableCounter (Loop Index) is
incremented at the bottom of the loop on each iteration
Step value specifies the amount to change the Counter◦Step can be a negative number
CType FunctionCType FunctionConverts object from one type to
anotherCType (ValueToConvert,
NewType)Example
Dim radSelected as RadioButtonradSelected = CType(sender, RadioButton)Select Case radSelected . Name
Case "radBlue". . .
PrintingPrintingPrintDocument v.
PrintPreviewDialogUsing Graphics
◦Role of ‘e’ (event argument)◦Managing print area
ArraysArraysList or series of values all
referenced by the same nameUse an array to keep a series of
variables for later processing such as ◦Reordering◦Calculating◦Printing
Array TermsArray TermsElement
◦Individual item in the arrayIndex (or subscript)
◦Zero based number used to reference the specific elements in the array
◦Must be an integerBoundaries
◦Lower Subscript, 0 by default◦Upper Subscript
For Next LoopFor Next LoopReads in order of position in
array
Dim intCounter, intEnd as IntegerintEnd = strNames.GetUpperBound(0)For intCounter = 0 to intEnd
Console.Writeline(strNames(intCounter))Next
For Each LoopFor Each LoopReads based on position of
member in memory
Dim strItem as StringFor Each strItem in strNames
Console.Writeline(strItem)Next
ReDimReDimUse the ReDim keyword to
change the length of the array◦Can increase or decrease the
number of elements◦Can keep existing values of elements
using Preserve
ReDim Preserve strNames(19)
StructureStructureAllows multiple values and
procedures to be described as a data type
Similar to defining a table in a database
Does not need to be instantiated as a class does