In this program (VB, ASP.NET 2010) I create three fields: accno, name and balance, and the following buttons: create, destroy, set and get.
But while clicking on set or get method it gives the following exception: object reference not set to an instance of an object
Default.aspx.vb
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim obj As account 'declaring the obj of class account
    Protected Sub btn_create_Click(sender As Object, e As System.EventArgs) Handles btn_create.Click
        obj = New account 'initializing the object obj on class accounts
    End Sub    
    Protected Sub btn_set_Click(sender As Object, e As System.EventArgs) Handles btn_set.Click
        'sending the values from textboxes to accounts class through method setdata
        Try
            obj.setdata(CInt(txt_accno.Text), (txt_name.Text), CInt(txt_bal.Text))
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Protected Sub btn_get_Click(sender As Object, e As System.EventArgs) Handles btn_get.Click
        'calling the method getdata to view the output
        Try
            obj.getdata()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Protected Sub btn_destroy_Click(sender As Object, e As System.EventArgs) Handles btn_destroy.Click
        'calling the constructor
        obj = Nothing
    End Sub
End Class
Account.vb
Imports Microsoft.VisualBasic
Public Class account
    Private accno As Integer
    Private acc_name As String
    Private bal As Integer
    'constructor
    Public Sub New()
        MsgBox("object created")
    End Sub
    'public method to populate above three private variable
    Public Sub setdata(ByVal a As Integer, ByVal b As String, ByVal c As Integer)
        Me.accno = a
        Me.acc_name = b
        Me.bal = c
    End Sub
    Public Sub getdata()
        MsgBox(Me.accno.ToString + vbNewLine + Me.acc_name + vbNewLine + Me.bal.ToString)
    End Sub
    'destructor
    Protected Overrides Sub finalize()
        MsgBox("object destroyed")
    End Sub
End Class
 
     
     
    