Home >>VB.Net Built-in Functions >VB.Net program create a Student class and read and print details

VB.Net program create a Student class and read and print details

Write a VB.Net program create a Student class and read and print details

Here, we will create a student class on the console screen, then read and print student information.

Program :

Below is the source code for creating a student class and reading and printing student detail. The program given is compiled and successfully executed.

'VB.Net program to create a Student class and

'read and print Student detail.

Class Student
    Private roll_no As Integer
    Private name As String
    Private fees As Integer
    Private address As String
    Sub ReadInfo()
        Console.Write("Enter roll number: ")
        roll_no = Integer.Parse(Console.ReadLine())
        Console.Write("Enter student name: ")
        name = Console.ReadLine()
        Console.Write("Enter student fees: ")
        fees = Integer.Parse(Console.ReadLine())
        Console.Write("Enter student address: ")
        address = Console.ReadLine()
    End Sub
    Sub PrintInfo()
        Console.WriteLine("Student Information")
        Console.WriteLine(vbTab & "Roll Number: " & roll_no)
        Console.WriteLine(vbTab & "Roll Name  : " & name)
        Console.WriteLine(vbTab & "Fees       : " & fees)
        Console.WriteLine(vbTab & "address    : " & address)
    End Sub
End Class
Module Module1
    Sub Main()
        Dim S As New Student
    End Sub
End Module
Enter roll number: 10
Enter student name: Shweta pal
Enter student fees: 15000
Enter student address: Noida
Student Information
Roll Number: 10
Roll Name : Shweta pal
Fees : 15000
address : Noida

We created a Module1 module in the program above that includes the Main() function. Here, we built a Student Class class that includes roll-no, name, fees, address of 4 data members. We built two ReadInfo() and PrintInfo() methods in the student class ().

To read the student information from the user, the ReadInfo() method is used. The PrintInfo() method is used on the console screen to print student details.

The Main() method is the program's entry point, where we created the Student class object then called ReadInfo() and PrintInfo() using an object to read and print student information.

No Sidebar ads