Results 1 to 8 of 8

Thread: problem referencing a form

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    problem referencing a form

    ok, I followed the direction for mimicking a global form from here:

    http://msdn.microsoft.com/library/de...adingToNET.asp

    I have followed the instructions to a 'T'. I created a Sub Main() in my module for my functions. I set the startup object to load sub main first.

    in the sub main, I placed the code to instantiate the class just like the page said.

    I get an error: object reference not set to an instance of an object
    whn trying to manipulate a listview my calling it this way:

    MainForm.Ticketing.tab_TrblHistory_lvwTroubleHistory.Items.Add(History(intCount).TicketNumber)


    MainForm is the class, ticketing is the property and rest is the control I'm trying to add a row to.

    What am I missing here?

    Last edited by Andy; Apr 8th, 2004 at 11:08 AM.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Dear Ninja, might you insert the code that declare and instance the form?
    It should be like this, I assume:

    Public FrmReg As New FrmRegistrazioni


    If it's so and if your program step trough this code (put a break and verify) you should not have any problem.

    Waiting for your news.....
    Live long and prosper (Mr. Spock)

  3. #3
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Excuse me, Andy, I confused your nick!!!
    I have seen another thread just few seconds before and my memory failed!
    Live long and prosper (Mr. Spock)

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ninja IS a cool nickname!!


    VB Code:
    1. Sub main()
    2.  
    3.         Dim MainApp As New frmTicketingMain
    4.         MainApp.Showdialog()
    5.         MainForm.Ticketing = MainApp
    6.  
    7.     End Sub


    That is where my program enters and "MainApp" is supposed to be the only form visible.

    frm TicketingMain is the actual form that I created and it is the application. MainForm is the class and ticketing is the property. here is the class and property:

    VB Code:
    1. Public Class MainForm
    2.     'Purpose    :   sets up a "global" instance of the application
    3.     'Accepts    :  
    4.     'Returns    :  
    5.     'Notes      :  
    6.  
    7.  
    8.     Private Shared m_MainForm As frmTicketingMain
    9.  
    10.  
    11.     Public Shared Property Ticketing() As frmTicketingMain
    12.         Get
    13.             Return m_MainForm
    14.         End Get
    15.         Set(ByVal Value As frmTicketingMain)
    16.             m_MainForm = Value
    17.         End Set
    18.     End Property
    19.  
    20. End Class

    here is where I get the error:
    VB Code:
    1. MainForm.Ticketing.ListView1.Items.Add(Object1(intCount).ItsProperty)


    I gave the names as you see them for clarity.

    I have tried other things with that last statement such as writing to a text box on mainForm.ticketing or simply writing something to the console. I still get that error.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    hmm...I have discovered this: the property "Ticketing" is equal to Nothing. That's weird cause it IS equal to the frmTicketingMain UNTIL it gets to the location I pointed out (thelistview).

    what could be causing the object to lose it's property value?

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Declare MainApp outside of Sub Main, like a form level module. Declare it as Public if you plan on referencing it from any form outside your module.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ok. so I Won't need sub Main then, right? that's where the program gets fired off. If I declare it outside, I'll have declared it twice: once to show the form inside form main and then once again outside.

    I guess I could have the startup object as the main form? will that still work?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    alright!! Here's what I did:

    I took this out of sub main(): MainForm.Ticketing = MainApp

    I stuck that in the formLoad event of the main form and changed MainApp to say Me.

    works like it should now.

    geez....8 hours almost with this stinking problem!!!

    Thanks all

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