Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Public Class Form1
- Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
- Me.Close()
- End Sub
- Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
- radNew.Checked = False
- radPlaystation.Checked = False
- radUsed.Checked = False
- radWii.Checked = False
- radXbox.Checked = False
- lstGames.Items.Clear()
- lstInformation.Items.Clear()
- End Sub
- Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
- Dim strInputFile As String
- Dim strValidGames() As String
- Dim strLine As String
- Dim intQuantity As Integer = 1
- Dim intCount As Integer = 0
- Dim gameInfo As Game
- 'Add error capture if no button is checked
- gameInfo.strPlatform = checkPlatform()
- gameInfo.CharType = checkType()
- strInputFile = openFile()
- If strInputFile <> Nothing Then
- Dim strInputFileSplit As String() = strInputFile.Split(New Char() {vbNewLine})
- For Each strLine In strInputFileSplit
- ReDim Preserve gameInfo.strGameInfo(intCount)
- gameInfo.strGameInfo(intCount) = strLine
- intCount += 1
- Next
- strValidGames = getValidGames(gameInfo)
- populateListboxWithGames(strValidGames, gameInfo)
- Else
- End If
- End Sub
- Function openFile()
- Dim dlgOpenFile As New OpenFileDialog
- Dim Reader As StreamReader
- Dim strInputFile As String
- If dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then
- Reader = File.OpenText(dlgOpenFile.FileName)
- strInputFile = Reader.ReadToEnd()
- Reader.Close()
- Else
- MessageBox.Show("File was not found")
- strInputFile = Nothing
- End If
- Return strInputFile
- End Function
- Function checkPlatform()
- 'Returns the platform to check for (PS for playstation, XB for xbox, WI for Wii)
- Dim strPlatform As String = ""
- If radPlaystation.Checked = True Then
- strPlatform = "PS"
- elseIf radXbox.Checked = True Then
- strPlatform = "XB"
- elseIf radWii.Checked = True Then
- strPlatform = "WI"
- Else
- MessageBox.Show("You have not checked an option for the platform!")
- End If
- Return strPlatform
- End Function
- Function checkType()
- 'Returns the type of game to check for (N for new, U for used)
- Dim charType As Char = ""
- If radNew.Checked = True Then
- charType = "N"
- ElseIf radUsed.Checked = True Then
- charType = "U"
- Else
- MessageBox.Show("You have not checked an option for the type!")
- End If
- Return charType
- End Function
- Public Structure Game
- Dim strPlatform As String
- Dim strTitle As String
- Dim strGame As String
- Dim decPrice As Decimal
- Dim CharRating As Char
- Dim CharType As Char
- Dim strGameInfo() As String
- End Structure
- Private Sub lstGames_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstGames.SelectedIndexChanged
- Dim strValidGames() As String
- Dim gameInfo2 As Game
- gameInfo2.strGameInfo = getValidGames(gameInfo2)
- populateListboxWithInfo(gameInfo2.strGameInfo)
- End Sub
- Private Sub txtQuantity_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQuantitySelect.KeyPress
- If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
- e.Handled = True
- End If
- End Sub
- Sub populateListboxWithGames(ByRef strArrayValidGames, ByRef gameInfo)
- Dim intLenghtOfArray As Integer = strArrayValidGames.Length
- Dim intCount As Integer = 0
- Dim intArrayStore As Integer
- Do While intCount < intLenghtOfArray
- Dim strArraySplit() As String = strArrayValidGames(intCount).Split(New Char() {","c})
- strArrayValidGames(intArrayStore) = strArrayValidGames(intCount)
- lstGames.Items.Add(strArraySplit(6))
- intArrayStore += 1
- intCount += 1
- Loop
- End Sub
- Function getValidGames(ByRef gameInfo)
- Dim intLenghtOfArray As Integer
- Dim intCount As Integer = 0
- Dim strArrayValidGames() As String
- Dim intArrayStore As Integer
- intLenghtOfArray = gameInfo.strGameInfo.Length
- Do While intCount < intLenghtOfArray - 2
- Dim strArraySplit() As String = gameInfo.strGameInfo(intCount).Split(New Char() {","c})
- If strArraySplit(3) = gameInfo.CharType Then
- If strArraySplit(1) = gameInfo.strPlatform Then
- ReDim Preserve strArrayValidGames(intArrayStore)
- strArrayValidGames(intArrayStore) = gameInfo.strGameInfo(intCount)
- intArrayStore += 1
- End If
- End If
- intCount += 1
- Loop
- Return strArrayValidGames
- End Function
- Sub populateListboxWithInfo(ByRef strValidGames)
- Dim intCount As Integer = 0
- Dim intLengthOfArray As Integer = strValidGames.Length
- Do While intCount < intLengthOfArray - 1
- Dim strArraySplit() As String = strValidGames(intCount).Split(New Char() {","c})
- lstInformation.Items.Add("Rating: " & strArraySplit(2))
- lstInformation.Items.Add("Quantity: " & strArraySplit(4))
- lstInformation.Items.Add("Price (per item): " & strArraySplit(5))
- Loop
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement