Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Public Class Form1
    Dim a As Double
    Dim b As Double
    Dim c As Double
    Dim x As ClassLibrary1.Class1 // creating object

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a = Integer.Parse(TextBox1.Text)
        b = Integer.Parse(TextBox2.Text)
        TextBox3.Text = CStr(x.add(a, b)) //calling the value and print in textbox3
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label1.Text = x.time() //calling the value and print in lablel
    End Sub
End Class


class Library
Public Class Class1
    Private c As Double
    Private a As DateTime
    Dim b As DateTime

    ReadOnly Property add(ByVal a As Double, ByVal b As Double)
        Get
            c = a + b
            Return CStr(c)
        End Get
    End Property
    ReadOnly Property time()
        Get
            a = Today
            b = Now()
            Return CStr(b)
        End Get
    End Property
End Class
Posted
Updated 5-May-14 23:08pm
v2
Comments
Manas Bhardwaj 6-May-14 5:06am    
This is not a good question.

What is the problem and what have you tried?

For the error message, it's quite clear that somewhere you have a null object and you are trying to access it.
Vedat Ozan Oner 6-May-14 5:11am    
error says what happened. use the debugger to find where you get this error. https://www.google.com.tr/#q=object+reference+not+set+to+an+instance+of+an+object
Sanket Saxena 6-May-14 5:17am    
Dim x As ClassLibrary1.Class1 // creating object
This does not create any object.

1 solution

Look at your code:
VB
Dim x As ClassLibrary1.Class1 // creating object
...
Label1.Text = x.time() //calling the value and print in lablel

That doesn't "creating object" - it allocates a variable called "x" that can refer to an object. It doesn't create any object and assign the value to "x", it creates x and assigns Nothing to it.
Probably, what you want to say is:
VB
Dim x As New ClassLibrary1.Class1 // creating object
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900