user control problem

New to VB.NET

I have an application with 2 usercontrols on a Form called Main

Login and PhoneLog

When the app runs the phonelog is not visable and the login is.

I am able to login and hide the login control but the phonelog control will not change to visable.

I think this is a lack of the proper reference somewhere but I'm not sure.


I get an error on the Debug for this line of code inside the Login control.

****The Following code is from the Usercontrol Login:*******


Public Function AuthOK()
        Me.Hide()
        Dim frmMain As Main
        frmMain.PhoneLog1.Visible = True '**** This code breaks



    End Function

*****************************************
This is the Error:
An unhandled exception of type 'System.NullReferenceException' occurred in ManagementSystem.exe

Additional information: Object reference not set to an instance of an object.
*****************************************

Please Help
Josh



Here are my Imports and Inherits

Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Security.Cryptography
Imports System.Text
Imports System.Text.RegularExpressions

 Inherits System.Windows.Forms.UserControl


Answer this question

user control problem

  • brjali

    hehehe.  When one is in rush of an answer, this forum really takes time, unlike the public ms newsgroup.  If they really lack people, I can do it, part time, :p 
  • Apopka_Pilot

    A NullReferenceException occurs when you try to access the properties or methods of a variable that has not been initialized.
    Dim frmMain as Main

    ' It's not enough to declare the variable.
    ' It also needs to be initialized
    frmMain = new Main

    ' now frmMain is safe to use

  • cftdanny

    you forgot to instantiate the second form:

    Public Function AuthOK() 
    Me.Hide() 
    Dim frmMain As <b>New Main()</b>
    frmMain.PhoneLog1.Visible = True '**** This code breaks 

  • Shane Bell

    Darn these moderated forums :)  This doesn't happen when the post shows up immediately.
  • Doug Winters


    Dim frmMain As new Main 
                    ^


    Remco

  • user control problem