Results 1 to 5 of 5

Thread: Instance of an object

  1. #1

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243

    Instance of an object

    I am getting an "Object reference not set to an instance of an object" error on this code. I have searched the forums, but I cannot seem to find an example that is helping me. I am used to VB6, and trying to understand the basics of .NET

    This is in a module, and there is a label on the frmMain called lblTestOutput


    VB Code:
    1. Public Sub MakeChanges()
    2.         Dim f As New frmMain
    3.         If f.lblTestOutput.Text = "" Then
    4.             f.lblTestOutput.Text = "Button Pushed!"
    5.         Else
    6.             f.lblTestOutput.Text = ""
    7.         End If
    8.  
    9.     End Sub

    Also, I am wondering...

    what is the correct way to load up a form using "Sub Main?"
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    When you started that project, what kind of project did you choose?

    I have tried your code and it worked without error, although the app exits almost immediately after it starts (as predicted).
    I don't live here any more.

  3. #3

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    I chose a "Windows Application"
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  4. #4

    Thread Starter
    Addicted Member Beengie's Avatar
    Join Date
    Nov 2003
    Location
    Central Valley, CA
    Posts
    243
    I added "f.Show" to the code
    VB Code:
    1. Option Explicit On
    2. Option Strict Off
    3. Module mdlTesting
    4.     Private f As New frmMain
    5.     '   Public Sub Main()
    6.     '     Dim g As frmMain
    7.     '     Application.Run(g)
    8.     ' End Sub
    9.     Public Sub MakeChanges()
    10.         If f.lblTestOutput.Text = "" Then
    11.             f.lblTestOutput.Text = "Button Pushed!"
    12.         Else
    13.             f.lblTestOutput.Text = ""
    14.         End If
    15.         Console.WriteLine(f.lblTestOutput.Text)
    16.         f.Show()
    17.     End Sub
    18. End Module
    to the module, and now it shows up.
    But...
    Now I have two forms open now because I had to dimension "f" as "New".
    Isn't there a way to reference it without it being "New?"
    Or what do I need to do to correct this?
    Last edited by Beengie; Jul 1st, 2004 at 03:10 PM.
    BeengieHappy.Vaue = (SharksScore > OpponentsScore)

    Go Sharks!

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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