Link to home
Start Free TrialLog in
Avatar of ghomrigh
ghomrigh

asked on

VB.NET Easy Question- how do I load Form2 and UNLOAD form1

Hi everyone,

Visual Basic.NET is new to me- this question will make it obvious.  in Visual Basic 6 this was so easy.  

I have two forms Form1 and Form2.

I want to unload Form1 and load Form2.  I do not want to hide Form1 (I know how to hide it) but since I am not going to come back to it- I want to nload it.  Poof- make it go away.  It's a login form- I feel better knowing its gone.

I am used to unloading it in the same proceedure that I start the next one.  I can live without doing that.   I'm still in VB 6 thinking mode.  Help me out of it.

So here it is:  how do I load Form2 and UNLOAD form1 in VB.NET?

You rock if you've got the right answer.
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

in VB.NET all forms are really classes, and you need to create an INSTANCE of the form class:

Dim MyForm as New Form1
MyForm.Visible = True

then you can also set

MyForm = Nothing

to get rid of it.

AW
also, you will be much better off, if you can stop thinking in VB 6 terms, as soon as possible.  VB.NET is NOT simply VB 6 on steroids.  VB.NET has a completely different PARADIGM - way of thinking about things.  It is not enough to try to use the same techniques that you used with VB 6.  Those techniques will generally NOT work, with VB.NET.

VB.NET is all about Objects and classes and Object Oriented Programming.  The sooner you understand what classes are and how to use them and the fundamental techniques that apply to OOP, the better off you will be.

AW
Avatar of NetPointer
NetPointer

to close u can use

Me.close

Avatar of ghomrigh

ASKER

I'm not thinking in VB 6 now- I was joking- I wish I would have never said it.  

Here's my problem:

Sub Switch_forms()
            Me.Close() ' I want to close this form

            OpenDataentryForm() ' This instantiates the form2 as a class.

End sub   ' When I get to end sub, the whole project closes

How do I fix that?  I don't want to hide it, and I'm not a big modal fan.  Modal means inflexible.  I want to unload it.

If I hid the form I'm trying to close, it would work,but I'd rather it go away.  How?
ASKER CERTIFIED SOLUTION
Avatar of PhilipRocks
PhilipRocks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks alot PhillipRocks'

I was slowly getting to that conclusion.  You really helped me along though.

Yeah, I'm finding that I have to take a different approach to the language than what I'm used to doing.  I'm torn between wanting to hammer stuff out, and actually utilizing and learning VB.NET.

Teaching it to yourself is kind of a slow process, but it is as rewarding as it is frustrating.  One book and the internet is not enough- at least not for me.  I read that review of the book- I like it.  Sounds good- I'll pick that one up ASAP.

Thanks again and Happy Hollidays to everyone,

Greg
I just bought that book.  the author owes you a finder's fee.
:)
Glad it helped - and I'm sure the book will too.  

-Philip