To Notes

Lecture Summary for IT 236 on 6/22/06

 

Review Questions

  1. What is the precedence of these VB.Net operators:
    &   .   ( )   =   ^   <   *   +
    Ans: ( )   .   ^   +   *   &   = (comparison)   <   = (assignment)
    The comparison = and < have the same precedence.

  2. Name two methods that can use the format string #0.000.
    Ans: Double.ToString and WriteLine. The String.Format method can also use the format string.

  3. What is the difference between Public, Private and Dim?
    Ans: Public and Private variables are declared outside of any method, but inside of a class or module. A Public variable is accessible anywhere within the solution but a Private variable is accessible only within the class or module where it is defined. Dim refers to a local variable declared within a method. A local variable is only accessible within the method within which it is defined.

  4. What is the difference between an If statement and a While statement?
    Ans: An If statement is executed zero or one time. A While statement is repeatedly executed zero or more times until the condition is false.

  5. Which of these is correct?
    ElseIf     Else If     EndIf     End If
    Ans: ElseIf and End If are correct.

  6. Convert the following statements to a Select statement:
    If x = 3 Then
        y = "a"
    ElseIf 4 <= x And x <= 7 Then
        y = "b"
    Else
        y = "c"
    End If

    Ans:
    Select Case x
        Case 3
           y = "a"
        Case 4 To 7
           y = "b"
        Case Else
           y = "c"
    End Select

  7. Write an If..Else statement that writes Yes if CheckBox1 is checked and No otherwise.
    Ans:
    If CheckBox1.Checked Then
        WriteLine("Yes")
    Else
        WriteLine("No")
    End If

  8. Write a statement that writes True if CheckBox1 is checked and False otherwise.
    Ans:
    WriteLine(CheckBox1.Checked)

  9. What is the default event for the TrackBar control?
    Ans: Scroll

  10. Name five properties of the TrackBar control.
    Ans: Value, Maximum, Minimum, SmallChange, LargeChange, TickFrequency.

  11. Give two other ways of changing the location and size of a control besides setting its Left, Top, Width and Height properties separately.
    Ans: Represent these properties by x, y, w and h, respectively.
 

Boolean Expressions

 

Practice Problem

  1. Draw the variable trace table and predit the output.
    Dim x = 4, y As Integer = 9
    Dim f, g As Boolean
    f = (x + 5 >= y And Not y <> y) Or x + y - 3 = 9
    g = True And Not False
    WriteLine(f And Not g)

    Ans:
    f = (x + 5 >= y And Not y <> y) Or x + y - 3 = 9
      = (True And Not False) Or False
      = (True And True) Or False
      = True Or False = True

    g = True And Not False
      = True And True = True

    x y f g
    4 9 True True
    The output is
    f And Not g = True And Not True = True And False = False.

     

    Repetition

     

    Practice Problem

    1. Convert this While loop to a For loop:
      n = 5
      While n <= 20
          WriteLine(n & " " & n ^ 2)
          n = n + 3
      End While

      Answer:
      For n = 5 To 20 Step 3
          WriteLine(n & " " & n ^ 2)
      Next

     

    Arrays

     

    Practice Problem

    1. Rewrite the Arrays Example using For Each loops instead of For loops.

      Ans: The loops look like this:
      For Each x As Integer In a
          WriteLine(x & " " )
      Next

      For Each x As String In b
          WriteLine(x & " " )
      Next

     

    The Split Function

     

    Reading from a Text File

     

    The FlightInfo1 Project