Jay1b Posted September 14, 2003 Posted September 14, 2003 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? Quote
aewarnick Posted September 14, 2003 Posted September 14, 2003 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. Quote C#
*Experts* mutant Posted September 14, 2003 *Experts* Posted September 14, 2003 Dim c As New Class1 In case like this you should consider making your function shared so you dont have to create class instance everytime. Quote
Jay1b Posted September 14, 2003 Author Posted September 14, 2003 Excellent. Thank you once again. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.