Beginner VB

Moderators: None (Apply to moderate this forum)
Number of threads: 1244
Number of posts: 2990

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Next Button Close Current Form, Open Another Posted by shelzmike on 7 Oct 2008 at 9:54 AM
Okay, I am a student and am at the very end of my introductory VB class. I need to create a project and I already have what I am going to do in my mind. However, I am completeing one of the last assignments of regular work and sadly enough some of the very basic elements have been left out of this class.

So, we are just now going back and learning creating a splash page and multiplle forms.

Here is my set up, and this is very basic (as was instructed). I have a splash page (splashForm), and two pages (mainForm & thirdForm). I have created a startUp.vb that has the code to display the splash page first, then the main form after 5 seconds. Okay, so far so good - that all works.

Now, on my mainForm, I have one button - a Next button. The purpose is to open the next form - thirdForm.

On thirdForm, I have 2 buttons - one to go back to the mainForm and one to close the application.

Here is my delimma - I cannot figure out how to create the code so that when I click on the Next button on mainForm it will hide the main form window and open the thirdForm window. And then when I click back it does the opposite (hide thirdForm and show mainForm again).

I can get this functionality to only work half right. I can get it to display the new window, but it still shows the old one as well. Here is the code I am using.

Public Class mainForm

   ' handles Next Button's Click event
   Private Sub nextButton_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles nextButton.Click

      thirdForm.Show()
      Me.Hide()

   End Sub ' nextButton_Click
End Class ' mainForm



When I use this, it opens the thirdForm, but then both close immediately.

Here is my code for thirdForm:

Public Class thirdForm

   ' handled backButton's click event
   Private Sub backButton_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles backButton.Click

      ' close this for and go back to main form
      mainForm.Show()
      Me.Hide()

   End Sub ' backButton_Click

   ' handles close Button's click event
   Private Sub closeButton_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles closeButton.Click

      ' close this window, exit program
      Me.Close()
      mainForm.Close()

   End Sub ' closeButton_Click
End Class ' thirdForm 




So being that I am a beginner, I am probably either making a stupid error or am way off. Can someone please help me with this. By the way, I am sure there may be several ways to do this, so the simplest way would be best at this point. There is no other functionality on my forms other than a label that has text. I do understand the difference between modal and non-modal forms, but am not sure I am applying them correctly.

Thanks -

Mike

Report
Re: Next Button Close Current Form, Open Another Posted by BitByBit_Thor on 7 Oct 2008 at 8:42 PM
:
: Here is my delimma - I cannot figure out how to create the code so
: that when I click on the Next button on mainForm it will hide the
: main form window and open the thirdForm window. And then when I
: click back it does the opposite (hide thirdForm and show mainForm
: again).
:
: I can get this functionality to only work half right. I can get it
: to display the new window, but it still shows the old one as well.
: Here is the code I am using.
:

The code here works (I even tested it myself, just to be sure). The problem must be somewhere else (for instance in the sub that initially displays mainForm). If you could post that code as well, then we can probably solve this. Alternatively, and perhaps very educative, you could use the debugger to step through the program. Just press F8 and the program will start with debugging on, and you can go through your code step by step and see if the program-flow is correct.

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.