0% found this document useful (0 votes)
16 views3 pages

Bock Golf Lab 5

Uploaded by

antwida6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Bock Golf Lab 5

Uploaded by

antwida6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

'BOCK GOLF LAB 5

'DANIEL ANTWI
'30-08-2022

Option Strict On
Public Class Form1

'DECLARING GLOBAL VARIABLES FOR THE PROGRAM


Private Valid As Boolean
Private Price As Decimal
Private Quantity As Decimal
Private ItemValue As Decimal
Private TotalInventory As Decimal
Private Sub Form1_Load(sender As Object, e As EventArgs)
'SET FOCUS TO SELECTCOMBO BOX ON STARTUP
SelectItemComboBox.Focus()

End Sub

Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


ExitToolStripMenuItem.Click
'TO EXIT PROGRAM
Me.Close()
End Sub

Private Sub AddToItemListingToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles AddToItemListingToolStripMenuItem.Click
'Try CATCH BLOCK FOR EXECPTION HANDLING
Try
'CALLING THE FUNCTION VALIDDATA
ValidData()
'CHECK RETURN VALUE OF FUNCTION
''CALCULATE ITEM VALUE
'WRITE TEXT AND ITEM VALUE TO LISTBOX
'CLEAR TEXTBOXES,COMBOBOX, SET FOCUS TO COMBOBOX
'ERROR MESSAGES
If Valid = True Then
ItemValue = Quantity * Price
InventoryItemListBox.Text += SelectItemComboBox.Text & " - Qty : " &
CStr(QuantityTextBox.Text) & " - " & CStr(ItemValue) & ControlChars.NewLine
TotalInventory += ItemValue
TotalInventoryTextBox.Text = TotalInventory.ToString("C2")
SelectItemComboBox.SelectedIndex = -1
WholeSaleTextBox.Clear()
QuantityTextBox.Clear()
SelectItemComboBox.Focus()
SelectItemComboBox.Items.Clear()
Else
MessageBox.Show("Enter valid informtion", "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End If

Catch ex As Exception

MessageBox.Show("Enter valid informtion", "ERROR", MessageBoxButtons.OK,


MessageBoxIcon.Error)

End Try

End Sub
'CREATING A FUNCTION TO CHECK FOR VALID DATA

Private Function ValidData() As Boolean

Price = Decimal.Parse(WholeSaleTextBox.Text, Globalization.NumberStyles.Currency)


Quantity = Integer.Parse(QuantityTextBox.Text, Globalization.NumberStyles.Currency)
If SelectItemComboBox.Text = String.Empty Or WholeSaleTextBox.Text = String.Empty
Or Price <= 0 Or QuantityTextBox.Text = String.Empty Or Quantity <= 0 Then
Valid = False
Else
Valid = True
End If

Return Valid

End Function
'TO CLEAR THE FORM

Private Sub ClearItemListingToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles ClearItemListingToolStripMenuItem.Click
'ASK THE USER IF HE WANTS TO CLEAR THE FORM AND CLEAR IF YES IS CLICKED
Dim dialog As DialogResult = MessageBox.Show("Clear Inventory List?", "CLEAR
TEXTBOX", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If dialog = DialogResult.Yes Then

SelectItemComboBox.SelectedIndex = -1
SelectItemComboBox.Items.Clear()
WholeSaleTextBox.Clear()
QuantityTextBox.Clear()
TotalInventoryTextBox.Clear()
InventoryItemListBox.Items.Clear()
TotalInventory = 0
SelectItemComboBox.Focus()
End If

End Sub
'COUNTING NUMBER OF ITEMS IN THE COMBOBOX
Private Sub CountItemListingToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles CountItemListingToolStripMenuItem.Click
Dim number As Integer = SelectItemComboBox.Items.Count()
MessageBox.Show("There are " & number & "items in the select item box.", "ITEM
COUNT", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
'ADDING AN ITEM TO THECOMBOBOX

Private Sub AddItemToComboBoxToolStripMenuItem_Click(sender As Object, e As


EventArgs) Handles AddItemToComboBoxToolStripMenuItem.Click
Dim text As String = SelectItemComboBox.Text
If SelectItemComboBox.Text <> String.Empty Then
For Each Item In SelectItemComboBox.Items
If text Is Item.ToString Then
MessageBox.Show("Item already exists.", "INVALID ITEM NAME",
MessageBoxButtons.OK, MessageBoxIcon.Error)

Else
SelectItemComboBox.Items.Add(SelectItemComboBox.Text)
Exit For
End If
Next
Else
MessageBox.Show("Must enter a new item.", "INVALID ITEM NAME",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

End Sub
'DELETE AN ITEM FROM THE COMBOBOX

Private Sub DeleteComboBoxItemToolStripMenuItem_Click(sender As Object, e As


EventArgs) Handles DeleteComboBoxItemToolStripMenuItem.Click
If SelectItemComboBox.SelectedIndex = -1 Then
MessageBox.Show("Select an item to delete", "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Else
SelectItemComboBox.Items.RemoveAt(SelectItemComboBox.SelectedIndex)
End If
End Sub
'CHANGING BACKGROUND COLOR
Private Sub SetBackgroundColorToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles SetBackgroundColorToolStripMenuItem.Click, ColorsToolStripMenuItem.Click
ColorDialog1.Color = Me.BackColor
ColorDialog1.ShowDialog()
Me.BackColor = ColorDialog1.Color
End Sub
'CHANGING FONT
Private Sub SetFontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
SetFontToolStripMenuItem.Click, FontToolStripMenuItem.Click
FontDialog1.Font = Me.Font
FontDialog1.ShowDialog()
Me.Font = FontDialog1.Font
End Sub
'ABOUT MESSAGE
Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
AboutToolStripMenuItem.Click, ExitToolStripMenuItem1.Click
Dim day_time As String = "Daniel Antwi" & ControlChars.NewLine
day_time += DateTime.Now.ToString
MessageBox.Show(day_time, "ABOUT", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub

End Class

You might also like