Page 1 of 1

Different Types of Variable. Why you get "Object reference not set to an instance of an object Rate Topic: -----

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2239
  • View blog
  • Posts: 9,409
  • Joined: 29-May 08

Post icon  Posted 14 August 2009 - 11:30 AM

In vb.net the are different type of datatypes.

The first is a Value Type these are mostly involve the type to do with numbers. (Double, Integer etc)
Dim x As Double
At this point the variable x has the value of 0 the default value for a double.

The second is a Reference Type these are mostly involve classes but it includes Strings.
Dim s As String
Dim c As someClass
At this point the variables s & c don't have a value, they are set to Nothing, think of them as a pigeon hole for the value.

And this is the reason why you get the

Quote

Object reference not set to an instance of an object.


For a reference types you have at some point give the declaration an instance of the type.
For example
Dim s As String=""
Dim c As someClass = New someClass
or
Dim c As someClass
c = New someClass



Is This A Good Question/Topic? 0
  • +

Replies To: Different Types of Variable.

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2239
  • View blog
  • Posts: 9,409
  • Joined: 29-May 08

Posted 20 October 2009 - 04:17 PM

Note: If you pass a Reference Type to a function or subroutine via ByVal it is still a reference it is not a copy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1