Form Instantiation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Form Instantiation

  1. #1
    Join Date
    Aug 2010
    Posts
    41

    Question Form Instantiation

    I am 5 months into converting my project from VB6 to vb.net (don't ask) and have just re-organised to do it properly. To be specific, I am treating forms as a class rather than as in VB6 where you just take them for granted.

    I declare them, just like you would a string or an integer. So, what would you expect to happen in the following piece of code (be honest). Then see the screenshot below

    Code:
    Module Module1
    
    Friend MyForm1 As New Form1 
    
    Sub Main()
      MsgBox(MyForm1.Name)
    End Sub
    
    End Module
    So, why does that happen. Well, there is an excellent article here on auto instantiation:

    http://visualbasic.about.com/od/usin.../a/NewForm.htm

    but it does not really answer my question ...

    As for why Microsoft added "auto instantiation" my guess is that it is a bit of kludge to cater for the great unwashed ie VB6 programmers and they are rather embarrassed about it. The result, as far as I can see, is a mess. If you use auto instantiation you get some ambiguities and if you do it explicitly you also get some ambiguities ... but maybe I am totally wrong! I await elucidation from my betters ...

    .
    Attached Images Attached Images  
    Last edited by wavering; June 24th, 2014 at 04:02 AM.

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,844

    Re: Form Instantiation

    Well as I see it you are making a copy of Form1. I would not expect the name to change, it is assigned in the original Form1 properties.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Aug 2010
    Posts
    41

    Re: Form Instantiation

    Quote Originally Posted by DataMiser View Post
    Well as I see it you are making a copy of Form1. I would not expect the name to change, it is assigned in the original Form1 properties.
    LOL! I have wracked my brains trying work out what was happening but your explanation was staring me in the face and I could not see it.

    Apologies for wasting people's time ... I will go and find a hole to hide in ...

    But the article on "auto instantiation" (no connection to me) is well worth reading as this is important but obscure
    .
    Last edited by wavering; June 27th, 2014 at 02:59 AM.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center