Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem in invoking methods of a class

Problem in invoking methods of a class

Scheduled Pinned Locked Moved Visual Basic
helpdatabase
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aakkpp
    wrote on last edited by
    #1

    Hi, I have a problem in invoking a method in the class I have a Database class say DBAccess, in that I have a method to be invoked, I have created object to that class in this manner Dim objDBAccess as DBAccess when i used like this objDBAccess.GetData() Sometimes I am encountered with the error message "Object Reference not set to an Instance of an Object". I have overcomed by instantiating the object as Dim objDBAccess as New DBAccess I want to know how in some access the First statement itself worked fine and sometimes it failed on invoking that method.:confused:

    S D P R 4 Replies Last reply
    0
    • A aakkpp

      Hi, I have a problem in invoking a method in the class I have a Database class say DBAccess, in that I have a method to be invoked, I have created object to that class in this manner Dim objDBAccess as DBAccess when i used like this objDBAccess.GetData() Sometimes I am encountered with the error message "Object Reference not set to an Instance of an Object". I have overcomed by instantiating the object as Dim objDBAccess as New DBAccess I want to know how in some access the First statement itself worked fine and sometimes it failed on invoking that method.:confused:

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      it is very simple: for Eg: Dim thing as New Thing thing = Nothing ‘do something at start of load event if thing = “sandwich” Then thing = “jelly” Clearly the thing object is set to an instance of on object at this point. It’s an instance of the Thing class.

      Sathesh. Blessed is the season which engages the whole world in a conspiracy of love.

      1 Reply Last reply
      0
      • A aakkpp

        Hi, I have a problem in invoking a method in the class I have a Database class say DBAccess, in that I have a method to be invoked, I have created object to that class in this manner Dim objDBAccess as DBAccess when i used like this objDBAccess.GetData() Sometimes I am encountered with the error message "Object Reference not set to an Instance of an Object". I have overcomed by instantiating the object as Dim objDBAccess as New DBAccess I want to know how in some access the First statement itself worked fine and sometimes it failed on invoking that method.:confused:

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        This is basic programming concepts in OOP. I HIGHLY suggest picking up a book on VB.NET for beginners. Your first statement just created a variable that CAN contain a reference to an object of type DBAccess. When you define it, it doesn't actually reference any DBAcess object, it points to Nothing, or null in C#. Your second statement (with the "New" in it) does the same thing as the first statement in creating a variable that CAN point to an object of type, then it creates an instance of the DBAccess class, called an object, and points the variable at that instance. Now you can call the methods and properties on that object.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        1 Reply Last reply
        0
        • A aakkpp

          Hi, I have a problem in invoking a method in the class I have a Database class say DBAccess, in that I have a method to be invoked, I have created object to that class in this manner Dim objDBAccess as DBAccess when i used like this objDBAccess.GetData() Sometimes I am encountered with the error message "Object Reference not set to an Instance of an Object". I have overcomed by instantiating the object as Dim objDBAccess as New DBAccess I want to know how in some access the First statement itself worked fine and sometimes it failed on invoking that method.:confused:

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          aakkpp wrote:

          I am encountered with the error message "Object Reference not set to an Instance of an Object"

          Because you need to use the New keyword.

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

          1 Reply Last reply
          0
          • A aakkpp

            Hi, I have a problem in invoking a method in the class I have a Database class say DBAccess, in that I have a method to be invoked, I have created object to that class in this manner Dim objDBAccess as DBAccess when i used like this objDBAccess.GetData() Sometimes I am encountered with the error message "Object Reference not set to an Instance of an Object". I have overcomed by instantiating the object as Dim objDBAccess as New DBAccess I want to know how in some access the First statement itself worked fine and sometimes it failed on invoking that method.:confused:

            R Offline
            R Offline
            rprateek
            wrote on last edited by
            #5

            declaring an object is different from creating an instance of an object. Unless you get an instance of an object it is not ready to be used in oo environment. You have to go through some books and tutorials.

            Blog for Programmers

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups