Visual Studio CODE
Option Strict On
Option Explicit On
Public Class Form1
Dim YachtTypes As String
Public TotalHours As Single
Public count As Integer
Public TotalMoney As Single
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim HourRate As Single
Dim Hours As Single
Dim Price As Single
'calculate
Try
'validation for name input
If txtName.Text <> "" Then
'validation for hours input
If IsNumeric(txtHours.Text) Then
If CDec(txtHours.Text) >= 1 Then
' If Math.Floor(CDec(txtHours.Text)) = Math.Ceiling(CDec(txtHours.Text)) Then
If lstSizes.SelectedIndex <> -1 Then
If ddYacht.SelectedIndex <> -1 Then
'input
'177
Select Case lstSizes.SelectedIndex
Case Is = 0
HourRate = 95
Case 1
HourRate = 137
Case 2
HourRate = 160
Case 3
HourRate = 192
Case 4
HourRate = 250
Case 5
HourRate = 400
Case 6
HourRate = 550
End Select
Hours = CSng(txtHours.Text)
'processing
Price = CSng(HourRate * Hours)
'output
count = count + CInt(1)
txtTotal.Text = Price.ToString("C")
TotalHours = TotalHours + Hours
TotalMoney = TotalMoney + Price
Else
MessageBox.Show("Please select Yacht type.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ddYacht.Focus()
End If
Else
MessageBox.Show("Please select a yacht size.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
lstSizes.Focus()
End If
' Else
'MessageBox.Show("Please input a whole number for hours.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
' txtHours.Focus()
'End If
Else
MessageBox.Show("No number greater than 1 inputed for hours.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtHours.Focus()
End If
Else
MessageBox.Show("No number inputed for hours", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtHours.Focus()
End If
Else
MessageBox.Show("No name inputed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtName.Focus()
End If
Catch theException As Exception
MessageBox.Show("Something wrong happened with your input data. Please look over it and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtName.Focus()
End Try
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
'programming Exit of entire application
Application.Exit()
End Sub
Private Sub mnuEditAdd_Click(sender As Object, e As EventArgs) Handles mnuEditAdd.Click
'addes a yacht type if one inputed
If ddYacht.Text <> "" Then
ddYacht.Items.Add(ddYacht.Text)
Else
MessageBox.Show("Please enter a new Yacht type if you wish to add one.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub mnuEditRemove_Click(sender As Object, e As EventArgs) Handles mnuEditRemove.Click
'removeing items form yachit list
Dim YesNo As DialogResult
If ddYacht.Text <> "" Then
YesNo = MessageBox.Show("Are you sure you want to Delete Yacht type: " & ddYacht.Text & "?", "Are You Sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If YesNo = DialogResult.Yes Then
ddYacht.Items.Remove(ddYacht.Text)
End If
Else
MessageBox.Show("Please enter the Yacht type that you wish to remove.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub mnuEditDisplayIndex_Click(sender As Object, e As EventArgs) Handles mnuEditDisplayIndex.Click
'counts how many yacht types there are
Dim TotalItems As Integer
TotalItems = ddYacht.Items.Count
MessageBox.Show("The number of item(s) in the Yacht list is: " & ddYacht.Items.Count.ToString(), "Total Number of Yacht Types", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub mnuHelpAbout_Click(sender As Object, e As EventArgs) Handles mnuHelpAbout.Click
'showing about box
AboutBox1.ShowDialog()
End Sub
Private Sub mnuEditClear_Click(sender As Object, e As EventArgs) Handles mnuEditClear.Click
'uses clear button's code when clicked
Call btnClear_Click(sender, e)
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'reset all inputs and disselect list boxes
txtHours.Text = ""
txtName.Text = ""
txtTotal.Text = ""
lstSizes.SelectedIndex = -1
ddYacht.SelectedIndex = -1
txtName.Focus()
End Sub
Private Sub mnuFilePrintSummary_Click(sender As Object, e As EventArgs) Handles mnuFilePrintSummary.Click
'shows summary fourm
Form2.ShowDialog()
End Sub
Private Sub mnuFilePrintYacht_Click(sender As Object, e As EventArgs) Handles mnuFilePrintYacht.Click
'lists all yacht types
Form3.lblYacht.Text = ""
Dim TotalItems As Integer
Dim myindex As Integer
TotalItems = ddYacht.Items.Count
For myindex = 0 To (TotalItems - 1) Step 1
Form3.lblYacht.Text = Form3.lblYacht.Text & vbNewLine & CStr(ddYacht.Items(myindex))
Next
Form3.ShowDialog()
End Sub
End Class
Download Project 3 * Requires Microsoft Visual Studios 2013 or higher.