'Ted Schuck schuckt1@lasalle.edu '2-14-05 'This program will ask the user for the amount of time they spent in a parking garage 'and will calculate their hourly rate and will also add extra if they have an SUV Option Strict On Option Explicit On Public Class Form1 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 Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents MinuteText As System.Windows.Forms.TextBox Friend WithEvents CostText As System.Windows.Forms.TextBox Friend WithEvents TruckCheck As System.Windows.Forms.CheckBox Friend WithEvents CalcButton As System.Windows.Forms.Button Friend WithEvents ClearButton As System.Windows.Forms.Button Friend WithEvents QuitButton As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.TruckCheck = New System.Windows.Forms.CheckBox Me.Label4 = New System.Windows.Forms.Label Me.MinuteText = New System.Windows.Forms.TextBox Me.CostText = New System.Windows.Forms.TextBox Me.CalcButton = New System.Windows.Forms.Button Me.ClearButton = New System.Windows.Forms.Button Me.QuitButton = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, CType(((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic) _ Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(64, 8) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(216, 48) Me.Label1.TabIndex = 6 Me.Label1.Text = "Ted Schuck's Garage" Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(16, 88) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(104, 32) Me.Label2.TabIndex = 7 Me.Label2.Text = "Minutes" Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(16, 216) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(104, 32) Me.Label3.TabIndex = 9 Me.Label3.Text = "Total Cost" Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight ' 'TruckCheck ' Me.TruckCheck.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.TruckCheck.Location = New System.Drawing.Point(144, 136) Me.TruckCheck.Name = "TruckCheck" Me.TruckCheck.Size = New System.Drawing.Size(208, 48) Me.TruckCheck.TabIndex = 1 Me.TruckCheck.Text = "SUV, Truck, or Van" ' 'Label4 ' Me.Label4.Location = New System.Drawing.Point(0, 184) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(360, 32) Me.Label4.TabIndex = 8 Me.Label4.Text = "____________________________________" ' 'MinuteText ' Me.MinuteText.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.MinuteText.Location = New System.Drawing.Point(144, 88) Me.MinuteText.Name = "MinuteText" Me.MinuteText.Size = New System.Drawing.Size(136, 26) Me.MinuteText.TabIndex = 0 Me.MinuteText.Text = "" ' 'CostText ' Me.CostText.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.CostText.Location = New System.Drawing.Point(144, 216) Me.CostText.Name = "CostText" Me.CostText.ReadOnly = True Me.CostText.Size = New System.Drawing.Size(136, 26) Me.CostText.TabIndex = 2 Me.CostText.Text = "" ' 'CalcButton ' Me.CalcButton.Location = New System.Drawing.Point(8, 288) Me.CalcButton.Name = "CalcButton" Me.CalcButton.Size = New System.Drawing.Size(104, 48) Me.CalcButton.TabIndex = 3 Me.CalcButton.Text = "Calculate" ' 'ClearButton ' Me.ClearButton.Location = New System.Drawing.Point(128, 288) Me.ClearButton.Name = "ClearButton" Me.ClearButton.Size = New System.Drawing.Size(104, 48) Me.ClearButton.TabIndex = 4 Me.ClearButton.Text = "Clear" ' 'QuitButton ' Me.QuitButton.Location = New System.Drawing.Point(248, 288) Me.QuitButton.Name = "QuitButton" Me.QuitButton.Size = New System.Drawing.Size(104, 48) Me.QuitButton.TabIndex = 5 Me.QuitButton.Text = "Quit" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(10, 22) Me.BackColor = System.Drawing.Color.SteelBlue Me.ClientSize = New System.Drawing.Size(360, 358) Me.Controls.Add(Me.QuitButton) Me.Controls.Add(Me.ClearButton) Me.Controls.Add(Me.CalcButton) Me.Controls.Add(Me.CostText) Me.Controls.Add(Me.MinuteText) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.TruckCheck) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region 'Declaring variables for the whole program Const MINIMUM As Double = 5.0 Const MAXIMUM As Double = 10.0 Const TRUCKPRICE As Double = 2.0 Const RATE As Double = 1.0 Const HOUR As Integer = 60 Const MINHOUR As Integer = 180 Const MOSTHOURS As Integer = 420 Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click MinuteText.Text = "" CostText.Text = "" TruckCheck.Checked = False End Sub Private Sub QuitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitButton.Click Me.Close() End Sub Private Sub CalcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcButton.Click 'Variables used in this method Dim cost As Double Dim minutes As Integer Dim time As Double 'check to see if user entered a number If IsNumeric(MinuteText.Text) Then minutes = Convert.ToInt32(MinuteText.Text) 'check to see if additional fees are required If minutes > MINHOUR And minutes <= MOSTHOURS Then time = minutes - MINHOUR time = time / HOUR time = Math.Ceiling(time) cost = (time * RATE) + MINIMUM 'check to see if the maximum rate should be charged ElseIf minutes > MOSTHOURS Then cost = MAXIMUM 'check to see if the minimum rate applies ElseIf minutes > 0 Then cost = MINIMUM 'give error message if user entered anything else Else MsgBox("You haven't spent any time in the garage.", MsgBoxStyle.OKOnly, "Error") End If 'if the user has a large vehicle add the extra fee If TruckCheck.Checked = True Then cost = cost + TRUCKPRICE End If CostText.Text = cost.ToString("c") 'give error message if the user typed something other than a number ElseIf MinuteText.Text <> "" Then MsgBox("Please enter the number of minutes spent in the garage.", MsgBoxStyle.OKOnly, "Error") MinuteText.Text = "" CostText.Text = "" TruckCheck.Checked = False End If End Sub End Class