CSC 252 (MIS 385) Programming in Visual Basic

Assignment #2 Solutions

Chapter 2 True or False (page 91) - 5 points each

Chapter 2 Short Answer (page 92) - 10 points each

Programming Challenge #1 on page 37 - 40 points

Develop the Carpet Size VB application by completing steps 7 through 11 of the programming process.

See the solution to assignment #1 for a solution for steps 1 through 6 of the programming process.

Event procedure code

Public Class frmAssign2_CarpetSize

    Private Sub btnCalculate_Click(ByVal sender As System.Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnCalculate.Click

        Me.lblArea.Text = Me.txtLength.Text * Me.txtWidth.Text

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                              Handles btnExit.Click

        Me.Close()

    End Sub
End Class

Form designer code

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmAssign2_CarpetSize
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
     _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
     _
    Private Sub InitializeComponent()
        Me.lblLengthPrompt = New System.Windows.Forms.Label
        Me.lblWidthPrompt = New System.Windows.Forms.Label
        Me.lblAreaPrompt = New System.Windows.Forms.Label
        Me.txtLength = New System.Windows.Forms.TextBox
        Me.txtWidth = New System.Windows.Forms.TextBox
        Me.lblArea = New System.Windows.Forms.Label
        Me.btnCalculate = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'lblLengthPrompt
        '
        Me.lblLengthPrompt.AutoSize = True
        Me.lblLengthPrompt.Location = New System.Drawing.Point(26, 26)
        Me.lblLengthPrompt.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
        Me.lblLengthPrompt.Name = "lblLengthPrompt"
        Me.lblLengthPrompt.Size = New System.Drawing.Size(78, 26)
        Me.lblLengthPrompt.TabIndex = 0
        Me.lblLengthPrompt.Text = "Length"
        '
        'lblWidthPrompt
        '
        Me.lblWidthPrompt.AutoSize = True
        Me.lblWidthPrompt.Location = New System.Drawing.Point(26, 73)
        Me.lblWidthPrompt.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
        Me.lblWidthPrompt.Name = "lblWidthPrompt"
        Me.lblWidthPrompt.Size = New System.Drawing.Size(68, 26)
        Me.lblWidthPrompt.TabIndex = 1
        Me.lblWidthPrompt.Text = "Width"
        '
        'lblAreaPrompt
        '
        Me.lblAreaPrompt.AutoSize = True
        Me.lblAreaPrompt.Location = New System.Drawing.Point(26, 118)
        Me.lblAreaPrompt.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
        Me.lblAreaPrompt.Name = "lblAreaPrompt"
        Me.lblAreaPrompt.Size = New System.Drawing.Size(58, 26)
        Me.lblAreaPrompt.TabIndex = 2
        Me.lblAreaPrompt.Text = "Area"
        '
        'txtLength
        '
        Me.txtLength.Location = New System.Drawing.Point(134, 26)
        Me.txtLength.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
        Me.txtLength.Name = "txtLength"
        Me.txtLength.Size = New System.Drawing.Size(157, 32)
        Me.txtLength.TabIndex = 3
        '
        'txtWidth
        '
        Me.txtWidth.Location = New System.Drawing.Point(134, 73)
        Me.txtWidth.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
        Me.txtWidth.Name = "txtWidth"
        Me.txtWidth.Size = New System.Drawing.Size(157, 32)
        Me.txtWidth.TabIndex = 4
        '
        'lblArea
        '
        Me.lblArea.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblArea.Location = New System.Drawing.Point(134, 118)
        Me.lblArea.Margin = New System.Windows.Forms.Padding(6, 0, 6, 0)
        Me.lblArea.Name = "lblArea"
        Me.lblArea.Size = New System.Drawing.Size(157, 26)
        Me.lblArea.TabIndex = 5
        '
        'btnCalculate
        '
        Me.btnCalculate.Location = New System.Drawing.Point(31, 159)
        Me.btnCalculate.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
        Me.btnCalculate.Name = "btnCalculate"
        Me.btnCalculate.Size = New System.Drawing.Size(124, 44)
        Me.btnCalculate.TabIndex = 6
        Me.btnCalculate.Text = "Calculate"
        Me.btnCalculate.UseVisualStyleBackColor = True
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(167, 159)
        Me.btnExit.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(124, 44)
        Me.btnExit.TabIndex = 7
        Me.btnExit.Text = "Exit"
        Me.btnExit.UseVisualStyleBackColor = True
        '
        'frmAssign2_CarpetSize
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(12.0!, 25.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(317, 230)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnCalculate)
        Me.Controls.Add(Me.lblArea)
        Me.Controls.Add(Me.txtWidth)
        Me.Controls.Add(Me.txtLength)
        Me.Controls.Add(Me.lblAreaPrompt)
        Me.Controls.Add(Me.lblWidthPrompt)
        Me.Controls.Add(Me.lblLengthPrompt)
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 16.0!, _
            System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Margin = New System.Windows.Forms.Padding(6, 6, 6, 6)
        Me.Name = "frmAssign2_CarpetSize"
        Me.Text = "Carpet Size (assignment #2)"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents lblLengthPrompt As System.Windows.Forms.Label
    Friend WithEvents lblWidthPrompt As System.Windows.Forms.Label
    Friend WithEvents lblAreaPrompt As System.Windows.Forms.Label
    Friend WithEvents txtLength As System.Windows.Forms.TextBox
    Friend WithEvents txtWidth As System.Windows.Forms.TextBox
    Friend WithEvents lblArea As System.Windows.Forms.Label
    Friend WithEvents btnCalculate As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
End Class