Results 1 to 6 of 6

Thread: Loading form2

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37

    Loading form2

    What am I missing here, in Excel VB macro I can use load form2 and then form2.show to load and show a second form.

    With visual studio (vb) I have Form1 with a button, when you click the button I want to show Form2. All help files I've found do this;
    Dim formx as New Form()
    formx.ShowDialog()

    Sure, that works, but that gives an empty form, not my form.

    In my solution explorer I see Form1.vb and Form2.vb, but;

    load form2 changes to Load(Form2) with error;
    'Form2' is a type and cannot be used as an expression.

    form2.show changes to form2.show() with error;
    Reference to a non-shared member requires an object reference.

    I've also added;
    Imports projectname.Form2

    which exact use I do not know, but I thought it a declaration because perhaps Form2 isn't in my scope, but still doesn't work.



    In short, what are the code lines to load form2 from form1?

  2. #2
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Dear friend I have more than just one doubt about what are you trying to do. I try to go on my way, hoping it contains the answer you need

    First Step: I'm on a new peoject and I add a windows form to project. Default name that IDE proposes is Form1. I accept it, than I fill the form with, at least, a control...a button for example.

    Second Step: I add a second form. The default name is Form2. I'm very lucky...just the name I wanted . I put a label on that form ( an empty Form is not a nice thing to view )

    Third step: I come back on Form1 and click twice on the button. IDE put me into the click event routine of that button. I write this code:

    Dim F2 as new Form2
    F2.ShowDialog
    F2.Close
    F2.Dispose
    F2=Nothing

    Four step: In project Properties I set Form1 as starting object of the project (perhaps it's already so by default, I'm not sure )

    Fifth step: Run code and click on the button. F2 should have to appear....I hope
    It's possible I forget something. I'll correct if so
    Try this and let me know the result!
    Bye
    Live long and prosper (Mr. Spock)

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    Thanks for the solution

    I totally misunderstood what was happening, I thought I could use my form2 as an object, but it isn't an object, it's a 'blue print' of what I want my form to look like so i have to first create an instance of it by using;

    dim F2 as form2
    F2.showdialog

    while I was trying to use it directly with things like;

    form2.showdialog

    You can't use any form you create yourself, but you can create an instance of it and use that.

    Nice how something can seem so 100% logical after some help

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    The form you create in the IDE is a class. You have to instantiate an instance of the class to get an actual form.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Salvelinus is right, but I think you have already catched the meaning.
    Always happy to be useful....bye and good night!
    Live long and prosper (Mr. Spock)

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by cphoenixc
    Thanks for the solution

    I totally misunderstood what was happening, I thought I could use my form2 as an object, but it isn't an object, it's a 'blue print' of what I want my form to look like so i have to first create an instance of it by using;

    dim F2 as form2
    F2.showdialog

    while I was trying to use it directly with things like;

    form2.showdialog

    You can't use any form you create yourself, but you can create an instance of it and use that.

    Nice how something can seem so 100% logical after some help
    Just in case you missed it, should be:

    Dim F2 As NEW form2
    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