Option Explicit On Option Strict On Public Class Form1 Private Function PullInfo(ByVal fileContents As String, ByRef line As String, ByRef startPos As Integer) As Boolean Dim position As Integer position = fileContents.IndexOf(ControlChars.NewLine, startPos) If position = -1 Then ' wasn't found Return False Else ' was found - fill current line and update start position line = fileContents.Substring(startPos, position - startPos) startPos = position + 2 Return True End If End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' declare variables Dim allText As String Dim current As String Dim lineExists As Boolean Dim start As Integer If My.Computer.FileSystem.FileExists("DVDs.txt") Then allText = My.Computer.FileSystem.ReadAllText("DVDs.txt") Do lineExists = PullInfo(allText, current, start) If lineExists Then lstChoice.Items.Add(current) End If Loop Until Not lineExists Else MsgBox("Please ensure that DVDs.txt file is in the debug folder under the project") End If End Sub Private Sub btnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPay.Click If txtTitle.Text <> "" Then My.Computer.FileSystem.WriteAllText("purchases.txt", _ txtTitle.Text & _ "," & txtPrice.Text & "," & txtTax.Text _ & "," & txtTotal.Text & ControlChars.NewLine, True) Else MsgBox("Please select a movie before paying") End If End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click txtTitle.Clear() txtPrice.Clear() txtTax.Clear() txtTotal.Clear() End Sub Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub Private Sub lstChoice_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstChoice.SelectedIndexChanged Dim choice As String Dim title As String Dim priceStr As String Dim price As Double Dim commaPos As Integer Dim isConverted As Boolean Dim tax As Double Dim total As Double Const taxRate As Double = 0.07 choice = lstChoice.SelectedItem.ToString commaPos = choice.IndexOf(",") title = choice.Substring(0, commaPos) txtTitle.Text = title priceStr = choice.Substring(commaPos + 1) isConverted = Double.TryParse(priceStr, price) If isConverted Then txtPrice.Text = priceStr tax = price * taxRate total = price + tax txtTax.Text = tax.ToString("c2") txtTotal.Text = total.ToString("c2") Else MsgBox("Movie info is incorrect, please call for help") End If End Sub End Class