Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

At the moment i am just playing around with functions and i keep getting this annoying error message with the code below

 

 

'An unhandled exception of type 'System.NullReferenceException' occurred in Procedures and Functions - Hr 10.exe

 

Additional information: Object reference not set to an instance of an object.'

 

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
     Dim c As Class1
     Dim i As Integer

     i = c.ComputeLength("hELLO")
     MsgBox(i)

  End Sub

 

Public Class Class1

  Public Function ComputeLength(ByVal strText As String) As Integer
     Return strText.Length
  End Function


End Class 

 

Can someone please point me in the right direction?

Posted

The error means that an object is not created yet. You have declared here

Dim c As Class1

but you did not initialize it. You did not create it. You made it ready to be created.

c=new Class1(); - c# code, but vb is very similar.

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...