Midterm Review CIS-166
Objects Classes provide a template Properties define the characteristics and behaviors of an object Methods are procedures that come with an object – actions it already knows how to do
Variables & Constants Memory 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 Use Option Explicit makes sure that variables are declared (defined) Create using Dim or Public Variables initialized when created (setting beginning value)
Scoping variables Within a block Within a procedure Form level Application level
Enumerators Enumerators 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 1 st , 1 + prior value for each additional member
Converting Values Convert class Data type – Parse/TryParse CType Role of Option Strict
Operators Mathematical Precedence matters! ^ ; - ; *, / ; \ ; Mod ; +, - Relational < ; <= ; = ; >= ; > Logical Precedence matters! Not; And ; Or
If … Then If something is true, execute following commands Can test for more than one condition Else ElseIf Nested If … Then ‘ Is’ functions help testing
Case Structure Best 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
Procedures Subroutine: procedures that don’t return something Function: procedures that send back some data Properties: procedures that store, return, or both; accept a single argument Arguments are means to provide data to a procedure
Event Procedures Connect an action with instructions using  Handles Roles of sender and event What object Which event
Sharing an Event Procedure If 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 Controls ListBox: Simple List Box with or without scroll bars ComboBox List may allow for user to add new items List may &quot;drop down&quot; to display items in list Combines characteristics of a TextBox with a ListBox
Items 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 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)
Loops Repeating a series of instructions Each repetition is called an iteration Types of Loops Do: Use when the number of iterations is unknown For Next: Use when the number of iterations known
Do Loops Ends 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 Loops Use when you know the number of iterations Uses a numeric counter variable Counter (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 Function Converts object from one type to another CType ( ValueToConvert, NewType ) Example Dim radSelected as RadioButton radSelected = CType(sender, RadioButton) Select Case radSelected  .  Name Case &quot;radBlue&quot; .  .  .
Printing PrintDocument v. PrintPreviewDialog Using Graphics Role of ‘e’ (event argument) Managing print area
Arrays List or series of values all referenced by the same name Use an array to keep a series of variables for later processing such as  Reordering Calculating Printing
Array Terms Element Individual item in the array Index (or subscript) Zero based number used to reference the specific elements in the array Must be an integer Boundaries Lower Subscript, 0 by default Upper Subscript
For Next Loop Reads in order of position in array Dim intCounter, intEnd as Integer intEnd = strNames.GetUpperBound(0) For intCounter = 0 to intEnd Console.Writeline(strNames(intCounter)) Next
For Each Loop Reads based on position of member in memory Dim strItem as String For Each strItem in strNames Console.Writeline(strItem) Next
ReDim Use 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)
Structure Allows 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

CIS-166 Midterm

  • 1.
  • 2.
    Objects Classes providea template Properties define the characteristics and behaviors of an object Methods are procedures that come with an object – actions it already knows how to do
  • 3.
    Variables & 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
  • 4.
    Variable Use OptionExplicit makes sure that variables are declared (defined) Create using Dim or Public Variables initialized when created (setting beginning value)
  • 5.
    Scoping variables Withina block Within a procedure Form level Application level
  • 6.
    Enumerators Enumerators area way to manage related constants Messagebox buttons Type of transaction Value of a member must be an integer Value defaults to 0 for 1 st , 1 + prior value for each additional member
  • 7.
    Converting Values Convertclass Data type – Parse/TryParse CType Role of Option Strict
  • 8.
    Operators Mathematical Precedencematters! ^ ; - ; *, / ; \ ; Mod ; +, - Relational < ; <= ; = ; >= ; > Logical Precedence matters! Not; And ; Or
  • 9.
    If … ThenIf something is true, execute following commands Can test for more than one condition Else ElseIf Nested If … Then ‘ Is’ functions help testing
  • 10.
    Case Structure Bestalternative 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
  • 11.
    Procedures Subroutine: proceduresthat don’t return something Function: procedures that send back some data Properties: procedures that store, return, or both; accept a single argument Arguments are means to provide data to a procedure
  • 12.
    Event Procedures Connectan action with instructions using Handles Roles of sender and event What object Which event
  • 13.
    Sharing an EventProcedure If 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)
  • 14.
    Types of ListControls ListBox: Simple List Box with or without scroll bars ComboBox List may allow for user to add new items List may &quot;drop down&quot; to display items in list Combines characteristics of a TextBox with a ListBox
  • 15.
    Items Collection Listof 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
  • 16.
    Index Property Zerobased 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)
  • 17.
    Loops Repeating aseries of instructions Each repetition is called an iteration Types of Loops Do: Use when the number of iterations is unknown For Next: Use when the number of iterations known
  • 18.
    Do Loops Endsbased 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
  • 19.
    For Next LoopsUse when you know the number of iterations Uses a numeric counter variable Counter (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
  • 20.
    CType Function Convertsobject from one type to another CType ( ValueToConvert, NewType ) Example Dim radSelected as RadioButton radSelected = CType(sender, RadioButton) Select Case radSelected . Name Case &quot;radBlue&quot; . . .
  • 21.
    Printing PrintDocument v.PrintPreviewDialog Using Graphics Role of ‘e’ (event argument) Managing print area
  • 22.
    Arrays List orseries of values all referenced by the same name Use an array to keep a series of variables for later processing such as Reordering Calculating Printing
  • 23.
    Array Terms ElementIndividual item in the array Index (or subscript) Zero based number used to reference the specific elements in the array Must be an integer Boundaries Lower Subscript, 0 by default Upper Subscript
  • 24.
    For Next LoopReads in order of position in array Dim intCounter, intEnd as Integer intEnd = strNames.GetUpperBound(0) For intCounter = 0 to intEnd Console.Writeline(strNames(intCounter)) Next
  • 25.
    For Each LoopReads based on position of member in memory Dim strItem as String For Each strItem in strNames Console.Writeline(strItem) Next
  • 26.
    ReDim Use theReDim 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)
  • 27.
    Structure Allows multiplevalues 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

Editor's Notes

  • #3 CIS-166 Spring 2009 Midterm Review
  • #16 CIS-166 Spring 2009 Midterm Review