This is the first time I have used CSV files to hold my data.
I have created a DataTable in one of my classes as follows;
Public Class New_Yellow_Ball_Competition
Public YBResultsTable As DataTable = New DataTable()
Private Sub ResultsTable()
YBResultsTable.Columns.AddRange(New DataColumn() {
New DataColumn("Date", GetType(Date)),
New DataColumn("TeamNumber", GetType(Integer)),
New DataColumn("Player1", GetType(String)),
New DataColumn("P1Handicap", GetType(Integer)),
New DataColumn("P1Hole1", GetType(Integer)),
New DataColumn("P1Stab1", GetType(Integer)),
New DataColumn("YB1Lost", GetType(Boolean)),
New DataColumn("P1Hole2", GetType(Integer)),
.... some 230 plus columns
})
End Sub
End Class
However, I want to save the DataTable as a CSV file in another Class as follows;
Public Class MainMenu
Private Sub YellowBallNew_Click(sender As Object, e As EventArgs) Handles YellowBallNew.Click
New_Yellow_Ball_Competition.MdiParent = Me
New_Yellow_Ball_Competition.WindowState = FormWindowState.Maximized
New_Yellow_Ball_Competition.Show()
End Sub
Private Sub YellowBallClose_Click(sender As Object, e As EventArgs) Handles YellowBallClose.Click
Using writer As StreamWriter = New StreamWriter("dump.csv")
Rfc4180Writer.WriteDataTable(YBResultsTable, writer, True)
End Using
End Sub
End Class
but I get an error stating
YBResultsTable is not declared. It maybe inaccessible due to its protection level.
So how do I get the DataTable to be available in the MainMenu class?
The code works providing it is called from the class the DataTable was created in.