I need help with the following program a VB.NET program, named CS2340Lab2 The pr
ID: 3887487 • Letter: I
Question
I need help with the following program
a VB.NET program, named CS2340Lab2
The program has one form with 6 textboxes, 7 labels and 3 buttons.
The Form
1. The title is "Lab2" followed by your name.
2. The size of the form is (500, 450), the FormBorderStyle is FixedSingle and has no
ControlBox.
3. The WindowState is Normal and the StartPosition is CenterScreen.
The Top Label
4. The AutoSize property is True.
5. The text of the label is "PayRoll Program." The font size is 14, font name is Times New
Roman, and font style is underlined.
6. It is above other controls and horizontally centered.
The Six Pairs of Textboxes and Labels
7. Below the top label, there are three textboxes on the left and three textboxes on the right.
All textboxes have the default size, and there a label above each textbox.
8. The three textboxes on the left are displayed top-down, aligned on the left with the same distance between them. The same applies to the three textboxes on the right, and each one on the right is aligned on the top with one textbox on the left.
9. Each label is aligned on the left with the textbox below it. The texts of the labels are
"ID," "Hours," "Rate," "Gross Pay," "Deduction," and "Net Pay."
10. All the labels have the default font with the TextAlign being MiddleLeft .
11. The entire group of controls are centered both horizontally and vertically.
12. The three textboxes on the left are used to get input values.
a. TextAlign is Left.
b. ID must have at least one non-space character. c. Hours must be non-negative number.
d. Rate must be a positive number.
13. The three textboxes on the right are used to display output values.
a. TextAlign is Right.
b. All values must be in Currency format. c. All are ReadOnly.
d. BackColor is Window, same as those input textboxes.
The Buttons
14. The texts of the buttons are "COMPUTE," "RESET," and "EXIT." The underlined
characters are the access keys.
15. The three buttons are horizontally centered with the same distance between them.
16. Button COMPUTE is the AcceptButton and button EXIT is the CancelButton of the form.
The Click Events of the buttons
17. The program will check the input values when button COMPUTE is clicked.
The values will be checked top-down, and when one invalid value is found, the following will not be checked.
A message box will be displayed when one input value is found invalid, and the focus will go to the corresponding textbox.
For an empty ID, the message is
Enter the ID please!
For an invalid hours, the message must be on two lines as follows:
Invalid Hours!
Hours must be non-negative!
For an invalid rate, the message must be on two lines as follows:
Invalid Rate!
Rate must be positive!
18. If all input values are valid, the program will compute the Gross Pay, Deduction, and Net
Pay.
19. The Gross Pay is the product of Hours and Rate. But any hours above 40 are overtime hours and are paid one time and half of the regular Rate.
20. The Deduction is 33% of the Gross Pay, and the Net Pay is the difference of the Gross
Pay and the Deduction.
21. Remember that all output values must be displayed in the currency format.
22. The program will clear all textboxes and move the focus to the texbox for ID when button
RESET is clicked.
23. The program will terminate when button EXIT is clicked.
Tab Order
24. Textbox ID will have the focus when the program starts.
25. When the Tab key is pressed, the focus will go to textbox Hours, Rate, button
COMPUTE, RESET, EXIT , and then back to textbox ID.
26. The output textboxes on the right will not receive focus when the Tab key is pressed. (TabStop False)
Explanation / Answer
Form1.vb
Public Class Form1
Private Sub menuCompute_Click(sender As System.Object, e As System.EventArgs) Handles menuCompute.Click
Dim ID As String
Dim rate As Double
Dim hours As Double
Dim grossPay As Double
Dim deduction As Double
Dim net As Double
'check for valid ID
ID = txtID.Text.Trim
If ID = "" Then
MessageBox.Show("Enter the ID please!", "Lab ", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
Exit Sub
End If
'check for valid rate
If txtRate.Text.Trim = "" Then
MessageBox.Show("Invalid Rate!",
"Lab ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtRate.Focus()
Exit Sub
End If
rate = Convert.ToDouble(txtRate.Text.Trim)
If rate <= 0 Then
MessageBox.Show("Invalid Rate!",
"Lab ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtRate.Focus()
Exit Sub
End If
'Check for valid hours
If txtHours.Text.Trim = "" Then
MessageBox.Show("Invalid Hours!",
"Lab ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtHours.Focus()
Exit Sub
End If
hours = Convert.ToDouble(txtHours.Text.Trim)
If hours < 0 Then
MessageBox.Show("Invalid Hours!",
"Lab ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
'Calculate gross
Compute(rate, hours, grossPay, deduction, net)
txtGrossPay.Text = Format(grossPay, "c")
txtDeduction.Text = Format(deduction, "c")
txtNetPay.Text = Format(net, "c")
menuNext.Enabled = True
menuCompute.Enabled = False
txtID.ReadOnly = True
txtRate.ReadOnly = True
txtHours.ReadOnly = True
txtID.BackColor = SystemColors.Window
txtRate.BackColor = SystemColors.Window
txtHours.BackColor = SystemColors.Window
End Sub
Private Sub menuNext_Click(sender As System.Object, e As System.EventArgs) Handles menuNext.Click
txtDeduction.Text = ""
txtGrossPay.Text = ""
txtHours.Text = ""
txtID.Text = ""
txtNetPay.Text = ""
txtRate.Text = ""
txtID.Focus()
menuNext.Enabled = False
menuCompute.Enabled = True
txtID.ReadOnly = False
txtRate.ReadOnly = False
txtHours.ReadOnly = False
End Sub
Private Sub txtRate_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtRate.KeyPress
Select Case e.KeyChar
Case Chr(Keys.Back)
Case "0" To "9"
Case "."
If InStr(txtRate.Text, ".") > 0 Then
Beep()
e.Handled = True
End If
Case Else
Beep()
e.Handled = True
End Select
End Sub
Private Sub txtHours_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtHours.KeyPress
Select Case e.KeyChar
Case Chr(Keys.Back)
Case "0" To "9"
Case "."
If InStr(txtHours.Text, ".") > 0 Then
Beep()
e.Handled = True
End If
Case Else
Beep()
e.Handled = True
End Select
End Sub
Private Sub menuExit_Click(sender As System.Object, e As System.EventArgs) Handles menuExit.Click
If MessageBox.Show("This Program is going to terminate." + vbCrLf +
"Do you really want to exit?", "thank u", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) = DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub menuStats_Click(sender As System.Object, e As System.EventArgs) Handles menuStats.Click
Me.Hide()
frmStats.Show()
frmStats.BringToFront()
End Sub
Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If e.CloseReason = CloseReason.ApplicationExitCall Then
End
Else
e.Cancel = True
End If
End Sub
End Class
=============================================================================
Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
Private components As System.ComponentModel.IContainer
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.lblPayRoll = New System.Windows.Forms.Label()
Me.lblID = New System.Windows.Forms.Label()
Me.txtID = New System.Windows.Forms.TextBox()
Me.txtGrossPay = New System.Windows.Forms.TextBox()
Me.lblGrossPay = New System.Windows.Forms.Label()
Me.txtRate = New System.Windows.Forms.TextBox()
Me.lblRate = New System.Windows.Forms.Label()
Me.txtDeduction = New System.Windows.Forms.TextBox()
Me.lblDeduction = New System.Windows.Forms.Label()
Me.txtHours = New System.Windows.Forms.TextBox()
Me.lblHours = New System.Windows.Forms.Label()
Me.txtNetPay = New System.Windows.Forms.TextBox()
Me.lblNetPay = New System.Windows.Forms.Label()
Me.MenuStrip1 = New System.Windows.Forms.MenuStrip()
Me.FileToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.menuCompute = New System.Windows.Forms.ToolStripMenuItem()
Me.menuNext = New System.Windows.Forms.ToolStripMenuItem()
Me.menuStats = New System.Windows.Forms.ToolStripMenuItem()
Me.ToolStripSeparator1 = New System.Windows.Forms.ToolStripSeparator()
Me.menuExit = New System.Windows.Forms.ToolStripMenuItem()
Me.MenuStrip1.SuspendLayout()
Me.SuspendLayout()
'
'lblPayRoll
'
Me.lblPayRoll.AutoSize = True
Me.lblPayRoll.Font = New System.Drawing.Font("Times New Roman", 14.25!, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblPayRoll.Location = New System.Drawing.Point(173, 49)
Me.lblPayRoll.Name = "lblPayRoll"
Me.lblPayRoll.Size = New System.Drawing.Size(138, 21)
Me.lblPayRoll.TabIndex = 0
Me.lblPayRoll.Text = "PayRoll Program"
'
'lblID
'
Me.lblID.AutoSize = True
Me.lblID.Location = New System.Drawing.Point(89, 131)
Me.lblID.Name = "lblID"
Me.lblID.Size = New System.Drawing.Size(18, 13)
Me.lblID.TabIndex = 1
Me.lblID.Text = "ID"
Me.lblID.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtID
'
Me.txtID.Location = New System.Drawing.Point(92, 144)
Me.txtID.Name = "txtID"
Me.txtID.Size = New System.Drawing.Size(100, 20)
Me.txtID.TabIndex = 2
'
'txtGrossPay
'
Me.txtGrossPay.BackColor = System.Drawing.SystemColors.Window
Me.txtGrossPay.Location = New System.Drawing.Point(295, 144)
Me.txtGrossPay.Name = "txtGrossPay"
Me.txtGrossPay.ReadOnly = True
Me.txtGrossPay.Size = New System.Drawing.Size(100, 20)
Me.txtGrossPay.TabIndex = 4
Me.txtGrossPay.TabStop = False
Me.txtGrossPay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'lblGrossPay
'
Me.lblGrossPay.AutoSize = True
Me.lblGrossPay.Location = New System.Drawing.Point(292, 131)
Me.lblGrossPay.Name = "lblGrossPay"
Me.lblGrossPay.Size = New System.Drawing.Size(55, 13)
Me.lblGrossPay.TabIndex = 3
Me.lblGrossPay.Text = "Gross Pay"
Me.lblGrossPay.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtRate
'
Me.txtRate.Location = New System.Drawing.Point(92, 206)
Me.txtRate.Name = "txtRate"
Me.txtRate.Size = New System.Drawing.Size(100, 20)
Me.txtRate.TabIndex = 6
'
'lblRate
'
Me.lblRate.AutoSize = True
Me.lblRate.Location = New System.Drawing.Point(89, 190)
Me.lblRate.Name = "lblRate"
Me.lblRate.Size = New System.Drawing.Size(30, 13)
Me.lblRate.TabIndex = 5
Me.lblRate.Text = "Rate"
Me.lblRate.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtDeduction
'
Me.txtDeduction.BackColor = System.Drawing.SystemColors.Window
Me.txtDeduction.Location = New System.Drawing.Point(295, 206)
Me.txtDeduction.Name = "txtDeduction"
Me.txtDeduction.ReadOnly = True
Me.txtDeduction.Size = New System.Drawing.Size(100, 20)
Me.txtDeduction.TabIndex = 8
Me.txtDeduction.TabStop = False
Me.txtDeduction.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'lblDeduction
'
Me.lblDeduction.AutoSize = True
Me.lblDeduction.Location = New System.Drawing.Point(292, 190)
Me.lblDeduction.Name = "lblDeduction"
Me.lblDeduction.Size = New System.Drawing.Size(56, 13)
Me.lblDeduction.TabIndex = 7
Me.lblDeduction.Text = "Deduction"
Me.lblDeduction.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtHours
'
Me.txtHours.Location = New System.Drawing.Point(92, 265)
Me.txtHours.Name = "txtHours"
Me.txtHours.Size = New System.Drawing.Size(100, 20)
Me.txtHours.TabIndex = 10
'
'lblHours
'
Me.lblHours.AutoSize = True
Me.lblHours.Location = New System.Drawing.Point(89, 249)
Me.lblHours.Name = "lblHours"
Me.lblHours.Size = New System.Drawing.Size(35, 13)
Me.lblHours.TabIndex = 9
Me.lblHours.Text = "Hours"
Me.lblHours.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtNetPay
'
Me.txtNetPay.BackColor = System.Drawing.SystemColors.Window
Me.txtNetPay.Location = New System.Drawing.Point(295, 265)
Me.txtNetPay.Name = "txtNetPay"
Me.txtNetPay.ReadOnly = True
Me.txtNetPay.Size = New System.Drawing.Size(100, 20)
Me.txtNetPay.TabIndex = 12
Me.txtNetPay.TabStop = False
Me.txtNetPay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
'
'lblNetPay
'
Me.lblNetPay.AutoSize = True
Me.lblNetPay.Location = New System.Drawing.Point(292, 249)
Me.lblNetPay.Name = "lblNetPay"
Me.lblNetPay.Size = New System.Drawing.Size(45, 13)
Me.lblNetPay.TabIndex = 11
Me.lblNetPay.Text = "Net Pay"
Me.lblNetPay.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'MenuStrip1
'
Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.FileToolStripMenuItem})
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)
Me.MenuStrip1.Name = "MenuStrip1"
Me.MenuStrip1.Size = New System.Drawing.Size(494, 24)
Me.MenuStrip1.TabIndex = 16
Me.MenuStrip1.Text = "MenuStrip1"
'
Me.FileToolStripMenuItem.Name = "FileToolStripMenuItem"
Me.FileToolStripMenuItem.Size = New System.Drawing.Size(37, 20)
Me.FileToolStripMenuItem.Text = "&File"
'
'menuCompute
'
Me.menuCompute.Name = "menuCompute"
Me.menuCompute.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.C), System.Windows.Forms.Keys)
Me.menuCompute.Size = New System.Drawing.Size(166, 22)
Me.menuCompute.Text = "&Compute"
'
'menuNext
'
Me.menuNext.Enabled = False
Me.menuNext.Name = "menuNext"
Me.menuNext.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.N), System.Windows.Forms.Keys)
Me.menuNext.Size = New System.Drawing.Size(166, 22)
Me.menuNext.Text = "&Next"
'
'menuStats
'
Me.menuStats.Name = "menuStats"
Me.menuStats.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.S), System.Windows.Forms.Keys)
Me.menuStats.Size = New System.Drawing.Size(166, 22)
Me.menuStats.Text = "&Stats"
'
'ToolStripSeparator1
'
Me.ToolStripSeparator1.Name = "ToolStripSeparator1"
Me.ToolStripSeparator1.Size = New System.Drawing.Size(163, 6)
'
'menuExit
'
Me.menuExit.Name = "menuExit"
Me.menuExit.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.X), System.Windows.Forms.Keys)
Me.menuExit.Size = New System.Drawing.Size(166, 22)
Me.menuExit.Text = "E&xit"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(494, 422)
Me.ControlBox = False
Me.Controls.Add(Me.txtNetPay)
Me.Controls.Add(Me.lblNetPay)
Me.Controls.Add(Me.txtHours)
Me.Controls.Add(Me.lblHours)
Me.Controls.Add(Me.txtDeduction)
Me.Controls.Add(Me.lblDeduction)
Me.Controls.Add(Me.txtRate)
Me.Controls.Add(Me.lblRate)
Me.Controls.Add(Me.txtGrossPay)
Me.Controls.Add(Me.lblGrossPay)
Me.Controls.Add(Me.txtID)
Me.Controls.Add(Me.lblID)
Me.Controls.Add(Me.lblPayRoll)
Me.Controls.Add(Me.MenuStrip1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MainMenuStrip = Me.MenuStrip1
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Lab"
Me.MenuStrip1.ResumeLayout(False)
Me.MenuStrip1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents lblPayRoll As System.Windows.Forms.Label
Friend WithEvents lblID As System.Windows.Forms.Label
Friend WithEvents txtID As System.Windows.Forms.TextBox
Friend WithEvents txtGrossPay As System.Windows.Forms.TextBox
Friend WithEvents lblGrossPay As System.Windows.Forms.Label
Friend WithEvents txtRate As System.Windows.Forms.TextBox
Friend WithEvents lblRate As System.Windows.Forms.Label
Friend WithEvents txtDeduction As System.Windows.Forms.TextBox
Friend WithEvents lblDeduction As System.Windows.Forms.Label
Friend WithEvents txtHours As System.Windows.Forms.TextBox
Friend WithEvents lblHours As System.Windows.Forms.Label
Friend WithEvents txtNetPay As System.Windows.Forms.TextBox
Friend WithEvents lblNetPay As System.Windows.Forms.Label
Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip
Friend WithEvents FileToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents menuCompute As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents menuNext As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents menuStats As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents ToolStripSeparator1 As System.Windows.Forms.ToolStripSeparator
Friend WithEvents menuExit As System.Windows.Forms.ToolStripMenuItem
End Class
==========================================================================