KySoto

lab 10

Apr 27th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.64 KB | None | 0 0
  1. Option Explicit On
  2. Option Infer Off
  3. Option Strict On
  4. Public Class Form1
  5.     Dim inventory(50, 1) As Double
  6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7.         lstItems.Items.Add("Rake")
  8.         lstItems.Items.Add("Pitchfork")
  9.         lstItems.Items.Add("Titanium Machete")
  10.         inventory(0, 0) = 657
  11.         inventory(0, 1) = 9.99
  12.         inventory(1, 0) = 75060
  13.         inventory(1, 1) = 5.99
  14.         inventory(2, 0) = 25
  15.         inventory(2, 1) = 569.99
  16.         lstItems.SelectedIndex = 0
  17.     End Sub
  18.     Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click
  19.         Me.Close()
  20.     End Sub
  21.  
  22.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  23.         Dim checks As Boolean = False
  24.         Dim tempi As Integer
  25.         Dim tempd As Double
  26.         If lstItems.Items.Count > 49 Then
  27.             MsgBox("Inventory list full, please delete an item.", CType("Error", MsgBoxStyle), "Error")
  28.         Else
  29.             lstItems.Items.Add(InputBox("Please enter the item name", "Add item"))
  30.             Do While checks = False
  31.                 checks = Integer.TryParse(InputBox("Please enter the number of items in stock", "Add stock count"), tempi)
  32.             Loop
  33.             checks = False
  34.             Do While checks = False
  35.                 checks = Double.TryParse(InputBox("Please enter the price of your item", "Add price"), tempd)
  36.             Loop
  37.             inventory((lstItems.Items.Count - 1), 0) = tempi
  38.             inventory((lstItems.Items.Count - 1), 1) = tempd
  39.         End If
  40.  
  41.     End Sub
  42.  
  43.     Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
  44.         If lstItems.SelectedIndex >= 0 Then
  45.             MsgBox("There are " & inventory((lstItems.SelectedIndex), 0).ToString & " " & lstItems.SelectedItem.ToString & "(s) in stock at " & inventory((lstItems.SelectedIndex), 1).ToString("C2") & ".", , "Check stock")
  46.         Else
  47.             MsgBox("There is no item selected.", MsgBoxStyle.Critical, "Error")
  48.         End If
  49.     End Sub
  50.  
  51.     Private Sub btnDelte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelte.Click
  52.         Dim loc As Integer = lstItems.SelectedIndex
  53.         Dim length As Integer = lstItems.Items.Count - 1
  54.         Dim locOb As Object = lstItems.SelectedItem
  55.         If lstItems.SelectedIndex >= 0 Then
  56.             lstItems.Items.Remove(locOb)
  57.             For i As Integer = loc To length Step 1
  58.                 inventory(i, 0) = inventory(i + 1, 0)
  59.                 inventory(i, 1) = inventory(i + 1, 1)
  60.             Next
  61.             inventory(length, 0) = 0
  62.             inventory(length, 1) = 0
  63.             If lstItems.Items.Count > 0 Then
  64.                 lstItems.SelectedIndex = loc
  65.             End If
  66.         Else
  67.             MsgBox("There is no item selected.", MsgBoxStyle.Critical, "Error")
  68.         End If
  69.     End Sub
  70.  
  71.     Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
  72.         Dim checks As Boolean = False
  73.         Dim tempi As Integer
  74.         If lstItems.SelectedIndex >= 0 Then
  75.             Do While checks = False
  76.                 checks = Integer.TryParse(InputBox("Please enter the number of items in stock", "Edit stock count"), tempi)
  77.             Loop
  78.             inventory((lstItems.SelectedIndex), 0) = tempi
  79.         Else
  80.             MsgBox("There is no item selected.", MsgBoxStyle.Critical, "Error")
  81.         End If
  82.     End Sub
  83.  
  84.  
  85. End Class
Advertisement
Add Comment
Please, Sign In to add comment