' Overtime Example ' Input sequentially the hourly wage and total hours of each employee ' for a week. The current total salaries is displayed. 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 txtHourlyWage As System.Windows.Forms.TextBox Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents txtTotalHours As System.Windows.Forms.TextBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents txtTotalSalaries As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents btnUpdate As System.Windows.Forms.Button Friend WithEvents btnReset As System.Windows.Forms.Button Private Sub InitializeComponent() Me.txtHourlyWage = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.txtTotalHours = New System.Windows.Forms.TextBox Me.Label2 = New System.Windows.Forms.Label Me.txtTotalSalaries = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.btnUpdate = New System.Windows.Forms.Button Me.btnReset = New System.Windows.Forms.Button Me.SuspendLayout() ' 'txtHourlyWage ' Me.txtHourlyWage.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtHourlyWage.Location = New System.Drawing.Point(16, 16) Me.txtHourlyWage.Name = "txtHourlyWage" Me.txtHourlyWage.Size = New System.Drawing.Size(80, 26) Me.txtHourlyWage.TabIndex = 0 Me.txtHourlyWage.Text = "" ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(104, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(144, 24) Me.Label1.TabIndex = 1 Me.Label1.Text = "Hourly Wage" ' 'txtTotalHours ' Me.txtTotalHours.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtTotalHours.Location = New System.Drawing.Point(16, 48) Me.txtTotalHours.Name = "txtTotalHours" Me.txtTotalHours.Size = New System.Drawing.Size(80, 26) Me.txtTotalHours.TabIndex = 2 Me.txtTotalHours.Text = "" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(104, 48) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(144, 24) Me.Label2.TabIndex = 3 Me.Label2.Text = "Number Of Hours" ' 'txtTotalSalaries ' Me.txtTotalSalaries.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtTotalSalaries.Location = New System.Drawing.Point(16, 168) Me.txtTotalSalaries.Name = "txtTotalSalaries" Me.txtTotalSalaries.Size = New System.Drawing.Size(104, 26) Me.txtTotalSalaries.TabIndex = 4 Me.txtTotalSalaries.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(128, 168) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(128, 24) Me.Label3.TabIndex = 5 Me.Label3.Text = "Total Salaries" ' 'btnUpdate ' Me.btnUpdate.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnUpdate.Location = New System.Drawing.Point(16, 88) Me.btnUpdate.Name = "btnUpdate" Me.btnUpdate.Size = New System.Drawing.Size(240, 32) Me.btnUpdate.TabIndex = 6 Me.btnUpdate.Text = "Update Total Salaries" ' 'btnReset ' Me.btnReset.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnReset.Location = New System.Drawing.Point(16, 128) Me.btnReset.Name = "btnReset" Me.btnReset.Size = New System.Drawing.Size(240, 32) Me.btnReset.TabIndex = 7 Me.btnReset.Text = "Reset" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(280, 230) Me.Controls.Add(Me.btnReset) Me.Controls.Add(Me.btnUpdate) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.txtTotalSalaries) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.txtTotalHours) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.txtHourlyWage) Me.Name = "Form1" Me.Text = "Overtime" Me.ResumeLayout(False) End Sub #End Region ' Define global variable to keep track of current totalSalaries. Private totalSalaries = 0.0 Private Sub btnUpdate_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnUpdate.Click ' Define local variables for hourly wage and total hours. Dim w As Double = txtHourlyWage.Text Dim h As Double = txtTotalHours.Text ' Compute total salaries. If h > 40.0 Then totalSalaries += 40.0 * w + (h - 40.0) * w * 1.5 Else totalSalaries += h * w End If txtTotalSalaries.Text = totalSalaries End Sub ' Reset all textboxes and global variable. Private Sub btnReset_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnReset.Click txtHourlyWage.Clear() txtTotalHours.Clear() totalSalaries = 0.0 txtTotalSalaries.Clear() End Sub End Class