To Notes

Lecture Summary for IT 236 on 6/20/06

 

Review Questions

For questions 3, 4 and 5 see the Datatypes Table.

  1. What is a namespace?
    Ans: A namespace is a naming convention that organizes .NET items into related categories. Examples of namespaces are System, System.IO, System.Data, System.Xml.

  2. What is the size of an Integer variable? What is its maximum range?
    Ans: 4 bytes; 2^31, which is approximately 2 billion.

  3. What is the maximum length of a String?
    Ans: Over 2 billion bytes.

  4. How do you make a text box read only?
    Ans: Set its ReadOnly property to True.

  5. True or False: The name of an event handler looks like
    <NameOfControl>_<NameOfEvent>
    Ans: Strictly speaking false. Although this form of the event handler name is conventional, the name can be anything you wish. The Handles statement determines to which events the event handler responds.

  6. Name three ways other than clicking on a button to invoke the event handler registered to that button.
    Ans: (1) Clicking the space bar when the button has the focus, (2) Clicking the Enter key when the button is set as the AcceptButton for the form, (3) Invoking the PerformClick method of the button in the code.

  7. If x is defined as
    Dim x As Double = 0.005474
    write two format strings that will format x in these two ways:
    0.0055      .00548. Ans:
    "#0.0000"    "#.00000"

  8. If x is defined as
    Dim x As Double = 4583938.57463
    write two format strings that will format x in these two ways:
    4,583,938.57      4583938. Ans:
    "#,##0.##" "#0."

  9. Write a Windows application that will both increase the height and width of a clicked button by 10 pixels. Change the Height and Width properties of the button.
    Ans: If btnA is the name of the button, here is the event handler:
    Public Sub btnA_Click(ByVal sender As Object, _
      ByVal e As EventArgs) Handles btnA.Click

      btnA.Width = btnA.Width + 10
      btnA.Height = btnA.Height + 10

    End Sub

  10. Where do you put code in a Windows application that must run before any user input occurs.
    Ans: In the Form1_Load event handler.

 

Colors In VB.NET

 

Practice Problems

Set each of the specified properties at run time.

 

Formatting Data

 

Practice Problems

  1. Write a Windows application that inputs an amount and outputs the tax on that amount. The tax is computed as 8% of the amount. Format the output.

    Ans: See the Tax example.

  2. Write a Windows application that reads the number of credit hours, the total grade points (sum of A=4, B=3, etc times credit hours for each class). From this input information, compute the GPA and output the gpa, formatted to two digits behind the decimal point.

    Ans: See the Gpa1 example.

  3. Write a Windows application that reads
    (a) The x-coordinate of Point 1,
    (b) The y-coordinate of Point 1,
    (c) The x-coordinate of Point 2,
    (d) The y-coordinate of Point 2.
    Output the distance between the two points, using the distance formula that you learned in high school geometry. Format the output.

    Ans: See the Pythagorean example.

 

Using a Message Box

 

Structured Programming in VB.NET

 

More Controls

 

Practice Problem

  1. Write a Windows application with ScrollBar and PictureBox controls. Set the minimum and maximum values of the scroll bar to 0 and 255, respectively. When the scroll bar is moved from its minimum to maximum value, the background color of the picture box should change from red to pink to white. The various shades of the color pink can be obtained by the VB statement
    pinkShade = Color.FromArgb(255, x, x)
    where x is between 0 and 255 inclusive.

    Ans: See the Pink Example.

 

Private and Public Variables

 

Practice Problems

  1. Write a Windows application that inputs a sequence of numbers. Output the count of input numbers greater than 100. Describe the layout of your user interface and the event handlers that you need.

    Ans: See the Over90 example.

  2. Write a Windows application that inputs sequentially the letter grade and credit hours for courses. Output the student's grade point average.

    Ans: See the Gpa2 example.

 

The CurrencyConverter Project