
Private Sub cmdDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisplay.Click Dim message As String Dim mysr As StreamReader = File.OpenText("C:\product.txt") If File.Exists("C:\product.txt") Then print_inventory() Else message = "Either no file has yet been created or " message = message & "the file is not where expected." MessageBox.Show(message, "File Not Found", MessageBoxButtons.OK) End If End Sub Private Sub print_inventory() Dim item As String = "" Dim unit_price As Double Dim quantity As Double Dim supplier As String = "" Dim date_received As String = "" Dim total_price As Double Dim mysr As StreamReader = File.OpenText("C:\product.txt") Dim fmtStr As String = "{0, -25} {1, -25} {2, -25} {3, -25}{4, -25}{5, -20}" lstStock.Items.Add(String.Format(fmtStr, "Product", "Unit_Price", "Qty", "Date", "Supplier", "Total_Price")) Do While mysr.Peek <> -1 item = mysr.ReadLine unit_price = CDbl(mysr.ReadLine) quantity = CDbl(mysr.ReadLine) date_received = mysr.ReadLine supplier = mysr.ReadLine total_price = unit_price * quantity Dim fmtStr1 As String = "{0, -20} {1, -21} {2, -12}{3, -12}{4,-12}{5, -19}" lstStock.Items.Add(String.Format(fmtStr1, item, unit_price, quantity, date_received, supplier, total_price)) Loop MsgBox("Complete! All data is loaded!", MsgBoxStyle.Information, "Completion") mysr.Close() End Sub