Results 1 to 2 of 2

Thread: Object reference not set to an instance of an object.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    11

    Angry Object reference not set to an instance of an object.

    I am trying to write a .dll to use to pull up a text so I can count each character, word, paragraph, & sentence. When I trie dto use streamreader to open file I get this:
    System.NullReferenceException: Object reference not set to an instance of an object

    Here is the code that is getting error
    Dim stringProcessor As Course.Class1
    ofdMain.ShowDialog()
    stringProcessor.StringContents = txtRead.[Text]
    txtCharacters.[Text] = Microsoft.VisualBasic.CompilerServices.StringType.FromInteger(stringProcessor.Characters)
    txtWords.[Text] = Microsoft.VisualBasic.CompilerServices.StringType.FromInteger(stringProcessor.Words)
    txtSentences.[Text] = Microsoft.VisualBasic.CompilerServices.StringType.FromInteger(stringProcessor.Sentences)
    txtParagraphs.[Text] = Microsoft.VisualBasic.CompilerServices.StringType.FromInteger(stringProcessor.Paragraphs)
    Return

    Any help w/ this would be appreciated

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    This error generally means that you forgot to instantiate a new instance of the object.
    Which means that you forgot to use the "New" keyword.

    The code below will throw an error, because although myTextBox has been declared, it hasn't been instantiated as a new TextBox object.
    VB Code:
    1. Dim myTextBox As TextBox
    2.  
    3. myTextBox.Text = "Blah"

    This code will work
    VB Code:
    1. Dim myTextBox As TextBox
    2. myTextBox = New TextBox
    3.  
    4. or
    5.  
    6. Dim myTextBox As New TextBox
    7.  
    8. myTextBox.Text = "Blah"
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width