Linking Forms together by buttons

dserg

New member
Joined
Oct 13, 2005
Messages
3
Programming Experience
Beginner
Hi,
I have a program which the user needs to retrive and update information. I have 8 forms that I am trying to link to a main menu using buttons. I have been using this code but it just take the button to a new created form not my form that already exists.

Dim
listForm As Form
listForm.ShowDialog(
Me)
listForm.Show()

I don't know if I have to import the forms or something, I just don't know how to link them togther. Could anyone please offer advise.
Thanks in Advance:confused:

 
Is it MDI app? If it is so, then you should call the forms like this:

VB.NET:
Dim myForm as Form = New anExistingFormName
myForm.MDIParent = Me
myForm.Show() [COLOR=darkgreen]'the form named anExistingFormName will be shown[/COLOR]

also about the non MDI app:

VB.NET:
Dim myForm as Form = New anExistingFormName
myForm.ShowDialog() 'modal form 
[COLOR=darkgreen]'or[/COLOR]
myForm.Show() 'non-modal form

Regards ;)

p.s. maybe you are tring to call all forms at ones? let me know if it is so :)
 
Still no success

I used the code for the modal non MDI application and I placed it in the button in the menu that I want once clicked to display the form and this error appeared.


An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll
Additional information: Object variable or With block variable not set.

It allows the button to be pressed and it shows an empty form not the once I have designed.

I have seven buttons on a menu that all need to be coded to link to a different form that the user has to access. I have Dim each Form As Form at the top of the menu screen.

Thanks for your help

Kristy
 
You're probably getting the null reference because your dim statement is missing a "new". I.e. I think it should be:

Dim listForm As new Form

That's usually why I get those statements. I just managed to get information from one form to another today (a filename). This is what my code looks like:

VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] RenameButton_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] RenameButton.Click
[/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]   Dim[/COLOR][/SIZE][SIZE=2] renameForm1 [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] RenameForm
[/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][SIZE=2] [/SIZE]
[SIZE=2]   renameForm1.OldName = CurrentFilename
   renameForm1.ShowDialog()
 
[/SIZE][SIZE=2][COLOR=#0000ff]   If[/COLOR][/SIZE][SIZE=2] renameForm1.RenameOK [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]       CurrentFilename = renameForm1.NewNameBox.Text
[/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]   End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]   renameForm1.Dispose()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
.
Where my RenameForm is just simply a disabled textbox with the old name and a textbox to enter the new name. I put my own ok and cancel buttons on it. All they do is assign a boolean (renameok) to true if ok is pressed and false if cancel is pressed and they also have a "close()" line to hide the form after pressing the button (I also put a renameok=false line in the default dispose function but I don't know if I need it):

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OKButton_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] OKButton.Click
   RenameOK = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]   Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] CancelButton_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] CancelButton.Click
   RenameOK = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2]   Close()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
.
The thing that's key is that the information on the form isn't lost even after closing it with either button or the x on the top-right until I dispose it. I don't know if that helps or not but it does indicate that you can you send information back and forth even before and after the form is out of view.

If don't want to create a new form each time, then why not initialize all the forms in the beginning of the program with the dims up top (don't forget the new) without displaying them? Then for the button_clicks, just use the show dialog command without the dim statment and have close statements as needed if you don't just want them minimized.

Hope this helps.
 
Back
Top