Option Strict On Public Class frmMain Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If 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. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents txtHeight As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents txtWidth As System.Windows.Forms.TextBox Friend WithEvents txtOutput As System.Windows.Forms.TextBox Friend WithEvents btnCompute As System.Windows.Forms.Button Friend WithEvents btnExit As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label() Me.txtHeight = New System.Windows.Forms.TextBox() Me.Label3 = New System.Windows.Forms.Label() Me.txtWidth = New System.Windows.Forms.TextBox() Me.txtOutput = New System.Windows.Forms.TextBox() Me.btnCompute = New System.Windows.Forms.Button() Me.btnExit = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(24, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(256, 16) Me.Label1.TabIndex = 0 Me.Label1.Text = "Enter the lengths of the sides of your rectangle." ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(24, 48) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(40, 16) Me.Label2.TabIndex = 1 Me.Label2.Text = "Height" ' 'txtHeight ' Me.txtHeight.Location = New System.Drawing.Point(80, 48) Me.txtHeight.Name = "txtHeight" Me.txtHeight.Size = New System.Drawing.Size(64, 20) Me.txtHeight.TabIndex = 2 Me.txtHeight.Text = "" ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(24, 72) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(40, 24) Me.Label3.TabIndex = 3 Me.Label3.Text = "Width" ' 'txtWidth ' Me.txtWidth.Location = New System.Drawing.Point(80, 72) Me.txtWidth.Name = "txtWidth" Me.txtWidth.Size = New System.Drawing.Size(64, 20) Me.txtWidth.TabIndex = 4 Me.txtWidth.Text = "" ' 'txtOutput ' Me.txtOutput.Location = New System.Drawing.Point(16, 120) Me.txtOutput.Multiline = True Me.txtOutput.Name = "txtOutput" Me.txtOutput.ReadOnly = True Me.txtOutput.Size = New System.Drawing.Size(256, 128) Me.txtOutput.TabIndex = 5 Me.txtOutput.Text = "" ' 'btnCompute ' Me.btnCompute.Location = New System.Drawing.Point(192, 48) Me.btnCompute.Name = "btnCompute" Me.btnCompute.Size = New System.Drawing.Size(80, 48) Me.btnCompute.TabIndex = 6 Me.btnCompute.Text = "&Compute" ' 'btnExit ' Me.btnExit.Location = New System.Drawing.Point(24, 256) Me.btnExit.Name = "btnExit" Me.btnExit.Size = New System.Drawing.Size(248, 24) Me.btnExit.TabIndex = 7 Me.btnExit.Text = "E&xit" ' 'frmMain ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 285) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnExit, Me.btnCompute, Me.txtOutput, Me.txtWidth, Me.Label3, Me.txtHeight, Me.Label2, Me.Label1}) Me.Name = "frmMain" Me.Text = "Function Demo" Me.ResumeLayout(False) End Sub #End Region Function GetNumber(ByRef txtBox As TextBox) As Single '********************************************************************************************************** ' The purpose of this function is to return a single precision value from a text box. '********************************************************************************************************** Return CSng(txtBox.Text) End Function Function Area(ByVal sngSideA As Single, ByVal sngSideB As Single) As Double '********************************************************************************************************** ' The purpose of this function is to calculate the area of a rectangle '********************************************************************************************************** Return sngSideA * sngSideB End Function Function Hypotenuse(ByVal sngSideA As Single, ByVal sngSideB As Single) As Double '********************************************************************************************************** ' The purpose of this function is to return the length of the hypotenuse of a rectangle. '********************************************************************************************************** Return Math.Sqrt(sngSideA ^ 2 + sngSideB ^ 2) End Function Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click '********************************************************************************************************** ' The purpose of this procedure is to compute the area and the length of the hypotenuse of a rectangle. ' The functions Area and Hypotenuse are used. '********************************************************************************************************** Dim sngHeight As Single, sngWidth As Single Dim dblArea As Double, dblHypotenuse As Double Dim strTemp As String ' get the numbers sngHeight = GetNumber(txtHeight) sngWidth = GetNumber(txtWidth) ' calculate the area and hypotenuse dblArea = Area(sngHeight, sngWidth) dblHypotenuse = Hypotenuse(sngHeight, sngWidth) ' display output strTemp = "The rectangle with height " & CStr(sngHeight) & " and width " & sngWidth strTemp &= " has area " & CStr(dblArea) & " and hypotenuse " & dblHypotenuse & "." txtOutput.Text = strTemp End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click End ' halt End Sub End Class