this code works but where it says
Dim read As StreamReader = File.OpenText(FileNames(updatedSession))
an error message appears and i have no idea why
i also have to rewrite in to the text files each time a change has been done when the btnmove is pressed
can please be kind enough to debug it and finish it off beacause i have exams in week and dont have much time to go over it
THANKS
Imports System.IO
Public Class JMASS
Dim folderPath As String = "C:\Session"
Dim FileNames() As String
Dim Sessions() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counter, i, j As Integer
Dim files As _
System.Collections.ObjectModel.ReadOnlyCollection(Of String)
files = My.Computer.FileSystem.GetFiles(folderPath) ' allows the program to get all the text files in the folder
Dim reader As StreamReader
Dim sessionName As String
counter = CStr(files.Count) 'determines how many text files there are in the folder
ReDim FileNames(0 To (counter - 1))
ReDim Sessions(0 To (counter - 1))
'specifies the program the get all the text files from the start to end of the folder
'If a training session (text file) is added into the sessions folder and program will be able to read all the text files, complying with the scope of the program
'Assigning 0 to i
i = 0
While (i < counter)
reader = File.OpenText(files.Item(i))
FileNames(i) = files.Item(i)
j = 0
sessionName = ""
'reads all the names in a particular text file
Do While j < 3
reader.Peek()
sessionName = sessionName + " " + reader.ReadLine
j = j + 1
'reads the first 3 lines of each text file and ignores the rest
Loop
reader.Close()
cmbSession.Items.Add(sessionName)
Sessions(i) = sessionName
i = i + 1
'diplays the first three lines of each text file in the combo box
End While
End Sub
Private Sub lstSessions_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSession.SelectedIndexChanged
Dim selectedSession, i As Integer
selectedSession = cmbSession.SelectedIndex
'reads all the names in a particular text file and displays them in the listbox, except for the first first 3 lines
Dim reader As StreamReader = File.OpenText(FileNames(selectedSession))
lstNames.Items.Clear()
lstSessions.Items.Clear()
i = 0
Do While reader.Peek <> -1
If (i > 2) Then
lstNames.Items.Add(reader.ReadLine())
Else
reader.ReadLine()
End If
i = i + 1
Loop
reader.Close()
'Loads session names and absent list into a listbox giving the user the choice of moving a student to that class
Dim j As Integer
j = 0
Do While j < Sessions.Length
If (j <> selectedSession) Then
lstSessions.Items.Add(Sessions(j))
Else
lstSessions.Items.Insert(0, "Session Name")
End If
j = j + 1
Loop
End Sub
Private Sub lstupdate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSessions.SelectedIndexChanged
Dim updatedSession, i As Integer
updatedSession = lstupdate.SelectedIndex
Dim read As StreamReader = File.OpenText(FileNames(updatedSession))
lstupdate.Items.Clear()
i = 0
Do While read.Peek <> -1
If (i > 2) Then
lstupdate.Items.Add(read.ReadLine())
Else
read.ReadLine()
End If
i = i + 1
Loop
read.Close()
End Sub
Private Sub btnMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMove.Click
Dim entry As String = lstNames.SelectedIndex
If lstupdate.Items.Count > 10 Then
MsgBox("Each lesson may only have 10 students")
End If
lstNames.Items.Remove(entry)
lstupdate.Items.Add(entry)
End Sub
End Class
Dim read As StreamReader = File.OpenText(FileNames(updatedSession))
an error message appears and i have no idea why
i also have to rewrite in to the text files each time a change has been done when the btnmove is pressed
can please be kind enough to debug it and finish it off beacause i have exams in week and dont have much time to go over it
THANKS
Imports System.IO
Public Class JMASS
Dim folderPath As String = "C:\Session"
Dim FileNames() As String
Dim Sessions() As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim counter, i, j As Integer
Dim files As _
System.Collections.ObjectModel.ReadOnlyCollection(Of String)
files = My.Computer.FileSystem.GetFiles(folderPath) ' allows the program to get all the text files in the folder
Dim reader As StreamReader
Dim sessionName As String
counter = CStr(files.Count) 'determines how many text files there are in the folder
ReDim FileNames(0 To (counter - 1))
ReDim Sessions(0 To (counter - 1))
'specifies the program the get all the text files from the start to end of the folder
'If a training session (text file) is added into the sessions folder and program will be able to read all the text files, complying with the scope of the program
'Assigning 0 to i
i = 0
While (i < counter)
reader = File.OpenText(files.Item(i))
FileNames(i) = files.Item(i)
j = 0
sessionName = ""
'reads all the names in a particular text file
Do While j < 3
reader.Peek()
sessionName = sessionName + " " + reader.ReadLine
j = j + 1
'reads the first 3 lines of each text file and ignores the rest
Loop
reader.Close()
cmbSession.Items.Add(sessionName)
Sessions(i) = sessionName
i = i + 1
'diplays the first three lines of each text file in the combo box
End While
End Sub
Private Sub lstSessions_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSession.SelectedIndexChanged
Dim selectedSession, i As Integer
selectedSession = cmbSession.SelectedIndex
'reads all the names in a particular text file and displays them in the listbox, except for the first first 3 lines
Dim reader As StreamReader = File.OpenText(FileNames(selectedSession))
lstNames.Items.Clear()
lstSessions.Items.Clear()
i = 0
Do While reader.Peek <> -1
If (i > 2) Then
lstNames.Items.Add(reader.ReadLine())
Else
reader.ReadLine()
End If
i = i + 1
Loop
reader.Close()
'Loads session names and absent list into a listbox giving the user the choice of moving a student to that class
Dim j As Integer
j = 0
Do While j < Sessions.Length
If (j <> selectedSession) Then
lstSessions.Items.Add(Sessions(j))
Else
lstSessions.Items.Insert(0, "Session Name")
End If
j = j + 1
Loop
End Sub
Private Sub lstupdate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSessions.SelectedIndexChanged
Dim updatedSession, i As Integer
updatedSession = lstupdate.SelectedIndex
Dim read As StreamReader = File.OpenText(FileNames(updatedSession))
lstupdate.Items.Clear()
i = 0
Do While read.Peek <> -1
If (i > 2) Then
lstupdate.Items.Add(read.ReadLine())
Else
read.ReadLine()
End If
i = i + 1
Loop
read.Close()
End Sub
Private Sub btnMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMove.Click
Dim entry As String = lstNames.SelectedIndex
If lstupdate.Items.Count > 10 Then
MsgBox("Each lesson may only have 10 students")
End If
lstNames.Items.Remove(entry)
lstupdate.Items.Add(entry)
End Sub
End Class