Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27241

VS 2010 File Read Error

$
0
0
I keep getting my catch error for the main try " MessageBox.Show("Error reading file 'teams.txt' ")". Can someone please help me?

Code:

Public Class ReportForm

    Private Sub ReportForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim tempTeamName As String, tempTeamSize As Integer, tempWins As Integer, tempLosses As Integer, tempLevel As Integer, tempJoinDate As Date, tempLastPlayedDate As Date, tempWest As Boolean, tempCentral As Boolean, tempEast As Boolean, tempActive As Boolean, tempCountry As String, tempDate As Date, tempRegion As String, intReports As Integer, tempLevel2 As String

        Try
            FileOpen(1, "teams.txt", OpenMode.Input)
        Catch
            MessageBox.Show("File 'teams.txt' can't be opened, it may not exist or may be open in another program.")
        End Try

        Try
            ReportListView.View = View.Details

            ReportListView.Columns.Add("TeamName")
            ReportListView.Columns.Add("TeamSize")
            ReportListView.Columns.Add("Wins")
            ReportListView.Columns.Add("Losses")
            ReportListView.Columns.Add("Level")
            ReportListView.Columns.Add("JoinDate")
            ReportListView.Columns.Add("LastPlayedDate")
            ReportListView.Columns.Add("West")
            ReportListView.Columns.Add("Central")
            ReportListView.Columns.Add("East")
            ReportListView.Columns.Add("Active")
            ReportListView.Columns.Add("Country")


            Do While Not EOF(1)
                Input(1, tempTeamName)
                Input(1, tempTeamSize)
                Input(1, tempWins)
                Input(1, tempLosses)
                Input(1, tempLevel)
                Input(1, tempJoinDate)
                Input(1, tempLastPlayedDate)
                Input(1, tempWest)
                Input(1, tempCentral)
                Input(1, tempEast)
                Input(1, tempActive)
                Input(1, tempCountry)
                Input(1, tempDate)

                If tempWest = True Then
                    tempRegion = "West"
                ElseIf tempCentral = True Then
                    tempRegion = "Central"
                ElseIf tempEast = True Then
                    tempRegion = "East"
                End If

                If tempLevel = 0 Then
                    tempLevel2 = "Professional"
                ElseIf tempLevel = 1 Then
                    tempRegion = "Intermediate"
                ElseIf tempLevel = 2 Then
                    tempRegion = "Amateur"
                End If

                If tempDate = Today Then
                    Dim listItem1 As New ListViewItem(tempTeamName)

                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempTeamSize))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempWins))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempLosses))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempLevel))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempJoinDate))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempLastPlayedDate))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempWest))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempCentral))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempEast))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempActive))
                    listItem1.SubItems.Add(New ListViewItem.ListViewSubItem(listItem1, tempCountry))

                    ReportListView.Items.Add(listItem1)
                    ReportListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)

                    Try
                        FileOpen(2, "report.txt", OpenMode.Append)
                    Catch
                        MessageBox.Show("File 'report.txt' can't be opened, it may be open in another program.")
                    End Try

                    PrintLine(2, "Teams Information Report")
                    PrintLine(2, tempTeamName, TAB(20), tempTeamSize, TAB(37), tempWins, TAB(53), tempLosses, TAB(70), _
                    tempLevel2, TAB(86), tempJoinDate, TAB(100), tempLastPlayedDate, TAB(114), tempRegion, TAB(125), tempActive, TAB(140), tempCountry)

                    intReports += 1
                End If
            Loop
            If intReports > 0 Then
                PrintLine(2, intReports & " entries added on " & Today)
            End If

            FileClose(1)
            FileClose(2)
        Catch
            MessageBox.Show("Error reading file 'teams.txt' ")
        End Try

    End Sub

    Private Sub ReturnButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReturnButton.Click
        Application.Exit()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27241

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>