problem in redirecting forms

srivalli

Well-known member
Joined
May 4, 2005
Messages
189
Programming Experience
Beginner
i want to redirect from form1 to form2 .and when form2 is opened ,i want to close the form1.
the method i wrote in form 1 is

dim f as new form2
f.show()
me.close()

but without opening form2 the form is closed.
 
that's because form1 is the startup form and when the startup form is closed the application closes

what you need to do is start your application from Sub Main simply add a code module to the project and:

VB.NET:
Friend frmForm1 as Form1
Friend frmForm2 as Form2
Friend gblnExit as Boolean = False
Public Sub Main
  Do
	frmForm1 = New Form1
	Application.Run(frmForm1)
	frmForm2 = New Form2
	Application.Run(frmForm2)
  Loop Until gblnExit = True
End Sub

basically what this does is runs form1 and when you exit form1 it'll run form2 and when you exit form2 it'll run form1 again and so on unless you change gblnExit to true in either of the form's it'll continue to do form1 then form2

keep in mind this is the basics that shows the concept that you'll need
there are many ways of determining which form to run and when i usually use a select case against a string variable to determine which form is next (or when to exit the whole app) so enjoy

also you'll need to change the startup object to sub main instead of any of the forms as well
 
showing error while running.

i wrote the above code in code module and when i am running it .it is going to infinite loop.
what is the code to to jump from one form to other form2.
any code is there to write in form1 like that.
if so let me know.
can u be a bit clear.
artup form and when the startup form is closed the application closes

what you need to do is start your application from Sub Main simply add a code module to the project and:

VB.NET:
Friend frmForm1 as Form1
Friend frmForm2 as Form2
Friend gblnExit as Boolean = False
Public Sub Main
Do
	frmForm1 = New Form1
	Application.Run(frmForm1)
	frmForm2 = New Form2
	Application.Run(frmForm2)
Loop Until gblnExit = True
End Sub

basically what this does is runs form1 and when you exit form1 it'll run form2 and when you exit form2 it'll run form1 again and so on unless you change gblnExit to true in either of the form's it'll continue to do form1 then form2

keep in mind this is the basics that shows the concept that you'll need
there are many ways of determining which form to run and when i usually use a select case against a string variable to determine which form is next (or when to exit the whole app) so enjoy

also you'll need to change the startup object to sub main instead of any of the forms as well[/QUOTE]
 
another way to determin what form to run would be to use a select case:

VB.NET:
Friend frmForm1 as Form1
Friend frmForm2 as Form2
Friend gstrWhichForm as String = "Form1"
Friend gblnExit as Boolean = False
Public Sub Main
Do
  Select Case gstrWhichForm
	Case "Form1"
	  frmForm1 = New Form1
	  Application.Run(frmForm1)
	Case "Form2"
	  frmForm2 = New Form2
	  Application.Run(frmForm2)
	Case Else
	  gblnExit = True
End Select
Loop Until gblnExit = True
End Sub

'Somewhere in form1
gstrWhichForm = "Form2"

'Somewhere in form2
gstrWhichWindow = "SomethingElse"

what this does is starts with form1 then if form2 is needed you simply change the gstrWhichForm equal to "Form2" so when form1 is done it'll go to form2 if anywhere you need form1 again just change the variable equal to "Form1" again if it's set to anything other than "Form1" or "Form2" the Else branch will be used which exits the loop and ends the program

this is all simple logic and there are even more ways of determining which form to be using and when too
 
Back
Top