how to code button titled Open Student Details File.
When this button is clicked, do following: a) Open and read StudentDetails.txt and store the data into a StudentDetails structure array.
Imports System.IO
Public Class MainForm
Structure StudentDetails
Public StudentID As String
Public FirstName As String
Public LastName As String
Public Country As String
Public Responses As String
End Structure
Private student_Details() As StudentDetails
Private totalStudentDetails As Integer = 0
Private Sub btnOpenStudentDetailsFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenStudentDetailsFile.Click
Dim FilePath As String = "StudentDetails.txt"
Using reader As StreamReader = New StreamReader(FilePath)
' Read the number of students
Dim numberStudents As Integer = Integer.Parse(reader.ReadLine())
ReDim student_Details(numberStudents - 1)
For i As Integer = 0 To numberStudents - 1
Dim values() = reader.ReadLine().Split(",")
student_Details(i).StudentID = values(0)
student_Details(i).FirstName = values(1)
student_Details(i).LastName = values(2)
student_Details(i).Country = values(3)
student_Details(i).Responses = values(4)
totalStudentDetails += 1
Next
reader.Close()
End Using
End Sub
End Class
Comments
Leave a comment