Advertisement
Guest User

Structure help

a guest
May 22nd, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.81 KB | None | 0 0
  1. Imports System.IO
  2. Public Class Form1
  3.  
  4.     Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
  5.         Me.Close()
  6.     End Sub
  7.  
  8.     Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
  9.         radNew.Checked = False
  10.         radPlaystation.Checked = False
  11.         radUsed.Checked = False
  12.         radWii.Checked = False
  13.         radXbox.Checked = False
  14.  
  15.         lstGames.Items.Clear()
  16.         lstInformation.Items.Clear()
  17.     End Sub
  18.  
  19.     Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
  20.         Dim strInputFile As String
  21.         Dim strValidGames() As String
  22.         Dim strLine As String
  23.         Dim intQuantity As Integer = 1
  24.         Dim intCount As Integer = 0
  25.         Dim gameInfo As Game
  26.  
  27.         'Add error capture if no button is checked
  28.         gameInfo.strPlatform = checkPlatform()
  29.         gameInfo.CharType = checkType()
  30.         strInputFile = openFile()
  31.  
  32.         If strInputFile <> Nothing Then
  33.             Dim strInputFileSplit As String() = strInputFile.Split(New Char() {vbNewLine})
  34.  
  35.             For Each strLine In strInputFileSplit
  36.                 ReDim Preserve gameInfo.strGameInfo(intCount)
  37.                 gameInfo.strGameInfo(intCount) = strLine
  38.                 intCount += 1
  39.             Next
  40.  
  41.             strValidGames = getValidGames(gameInfo)
  42.             populateListboxWithGames(strValidGames, gameInfo)
  43.  
  44.         Else
  45.         End If
  46.     End Sub
  47.  
  48.     Function openFile()
  49.         Dim dlgOpenFile As New OpenFileDialog
  50.         Dim Reader As StreamReader
  51.         Dim strInputFile As String
  52.  
  53.         If dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then
  54.             Reader = File.OpenText(dlgOpenFile.FileName)
  55.             strInputFile = Reader.ReadToEnd()
  56.  
  57.             Reader.Close()
  58.         Else
  59.             MessageBox.Show("File was not found")
  60.             strInputFile = Nothing
  61.         End If
  62.  
  63.         Return strInputFile
  64.     End Function
  65.  
  66.     Function checkPlatform()
  67.         'Returns the platform to check for (PS for playstation, XB for xbox, WI for Wii)
  68.         Dim strPlatform As String = ""
  69.         If radPlaystation.Checked = True Then
  70.             strPlatform = "PS"
  71.         elseIf radXbox.Checked = True Then
  72.             strPlatform = "XB"
  73.         elseIf radWii.Checked = True Then
  74.             strPlatform = "WI"
  75.         Else
  76.             MessageBox.Show("You have not checked an option for the platform!")
  77.         End If
  78.  
  79.         Return strPlatform
  80.     End Function
  81.  
  82.     Function checkType()
  83.         'Returns the type of game to check for (N for new, U for used)
  84.         Dim charType As Char = ""
  85.         If radNew.Checked = True Then
  86.             charType = "N"
  87.         ElseIf radUsed.Checked = True Then
  88.             charType = "U"
  89.         Else
  90.             MessageBox.Show("You have not checked an option for the type!")
  91.         End If
  92.  
  93.         Return charType
  94.     End Function
  95.  
  96.     Public Structure Game
  97.         Dim strPlatform As String
  98.         Dim strTitle As String
  99.         Dim strGame As String
  100.         Dim decPrice As Decimal
  101.         Dim CharRating As Char
  102.         Dim CharType As Char
  103.         Dim strGameInfo() As String
  104.  
  105.     End Structure
  106.  
  107.     Private Sub lstGames_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstGames.SelectedIndexChanged
  108.         Dim strValidGames() As String
  109.         Dim gameInfo2 As Game
  110.  
  111.         gameInfo2.strGameInfo = getValidGames(gameInfo2)
  112.         populateListboxWithInfo(gameInfo2.strGameInfo)
  113.  
  114.     End Sub
  115.  
  116.     Private Sub txtQuantity_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuantitySelect.KeyPress
  117.         If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
  118.             e.Handled = True
  119.         End If
  120.     End Sub
  121.  
  122.     Sub populateListboxWithGames(ByRef strArrayValidGames, ByRef gameInfo)
  123.         Dim intLenghtOfArray As Integer = strArrayValidGames.Length
  124.         Dim intCount As Integer = 0
  125.         Dim intArrayStore As Integer
  126.  
  127.         Do While intCount < intLenghtOfArray
  128.             Dim strArraySplit() As String = strArrayValidGames(intCount).Split(New Char() {","c})
  129.             strArrayValidGames(intArrayStore) = strArrayValidGames(intCount)
  130.             lstGames.Items.Add(strArraySplit(6))
  131.             intArrayStore += 1
  132.             intCount += 1
  133.         Loop
  134.  
  135.     End Sub
  136.  
  137.     Function getValidGames(ByRef gameInfo)
  138.         Dim intLenghtOfArray As Integer
  139.         Dim intCount As Integer = 0
  140.         Dim strArrayValidGames() As String
  141.         Dim intArrayStore As Integer
  142.  
  143.         intLenghtOfArray = gameInfo.strGameInfo.Length
  144.         Do While intCount < intLenghtOfArray - 2
  145.             Dim strArraySplit() As String = gameInfo.strGameInfo(intCount).Split(New Char() {","c})
  146.  
  147.             If strArraySplit(3) = gameInfo.CharType Then
  148.                 If strArraySplit(1) = gameInfo.strPlatform Then
  149.                     ReDim Preserve strArrayValidGames(intArrayStore)
  150.                     strArrayValidGames(intArrayStore) = gameInfo.strGameInfo(intCount)
  151.                     intArrayStore += 1
  152.                 End If
  153.             End If
  154.             intCount += 1
  155.         Loop
  156.  
  157.         Return strArrayValidGames
  158.     End Function
  159.  
  160.     Sub populateListboxWithInfo(ByRef strValidGames)
  161.         Dim intCount As Integer = 0
  162.         Dim intLengthOfArray As Integer = strValidGames.Length
  163.  
  164.         Do While intCount < intLengthOfArray - 1
  165.             Dim strArraySplit() As String = strValidGames(intCount).Split(New Char() {","c})
  166.             lstInformation.Items.Add("Rating: " & strArraySplit(2))
  167.             lstInformation.Items.Add("Quantity: " & strArraySplit(4))
  168.             lstInformation.Items.Add("Price (per item): " & strArraySplit(5))
  169.         Loop
  170.  
  171.     End Sub
  172. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement