woodsrw Posted February 9, 2004 Posted February 9, 2004 I have FormA and FormB. FormA opens at startup, and a command button of FormA calls FormB. FormA remain open the entire time. When a command button is clicked on FormB, the value of a textbox on FormA is changed to "hello". I have looked around, and can not figure out the syntax to get this to work. I have tried doing the following. Dim newform as new FormA FormA.textbox.text = "hello" But, this opens a NEW FormA, and I want to edit the existing FormA. Does anyone know how to resolve this issue? Thank You. -Robert Quote
Administrators PlausiblyDamp Posted February 9, 2004 Administrators Posted February 9, 2004 http://www.xtremedotnettalk.com/showthread.php?s=&threadid=82585 Also could you please not double post your questions. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
woodsrw Posted February 9, 2004 Author Posted February 9, 2004 Solution doesn't work Thank you for your solutions, but they did not seem to work. I read the post, and attempted it before hand. The first solutions he gives mimics the problem of creating a new instance of FormA, which I don't want to do. The second option he suggests returns the following: --- An unhandled exception of type "System.NullReferenceException" ccrred in PROGRAM" Additional Information: Object reference nt set to an instance of an object. --- Any other ideas? BTW, after noticing that I accidently posted to ASP.NET, I attempted to delete it (but I do not have access to do so.)--- I hadn't realized I was in the wrong forums.. sorry for any inconvenience this caused you. Quote
Administrators PlausiblyDamp Posted February 9, 2004 Administrators Posted February 9, 2004 try the 3rd button down on this modified version - any use?forms.zip Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
woodsrw Posted February 10, 2004 Author Posted February 10, 2004 Solution doesn't work Thank you again, but the solution didn't work. Maybe I didn't write it clearly. Here's the deal FormA opens FormB. FormA remains open. FormB attempts to change the value of a textbox on FormA. I have attempted this: Dim myform as new Form myform.textbox.text = "hello" , but it OPENS A NEW FORMA. I want it to access the OLD FORMA. Thanks. robert Quote
Administrators PlausiblyDamp Posted February 10, 2004 Administrators Posted February 10, 2004 Did you look at the code behind the 3rd button down (labelled re-use form)? The form has a form level variable of type form3, the button checks if the form exists already and if it doesn't then it creates a new instance, if it already exists then the same instance is re-used. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
woodsrw Posted February 10, 2004 Author Posted February 10, 2004 retried code. I received the Unhandled Exception once again. To my interpretation, your code basically says this: If not open, create a new instance of formA If is open, create a new instance of formA If _form Is Nothing Then _form = New Form3 ElseIf _form.IsDisposed Then _form = New Form3 End If why bother with the if statement... The form is going to be open. (I understand it's error catching value at the end.. but for now I am trying to get this to work. You'd think a thing such as controlling an object on another page would've been easier to do. VB6 never seemed to have this many problems. Quote
Administrators PlausiblyDamp Posted February 10, 2004 Administrators Posted February 10, 2004 What line of code do you get the exception on? If _form Is Nothing Then _form = New Form3 ElseIf _form.IsDisposed Then _form = New Form3 End If _form.Show() _form.valueFromAnotherForm = TextBox1.Text the code says if _form hasn't been set (is nothing) then create a new instance. If a user closes the form (hitting the X for example) the _form variable will not be nothing but neither will the form be usable (_form.IsDisposed) - so create a new instance. Any other condition means we have a usable form instance so we just use it. Once you get the idea of object orientated code then you realise the little bit of extra work you have to do does result in a vastly more powerful / flexible language. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
woodsrw Posted February 10, 2004 Author Posted February 10, 2004 answer I got the error in _form.show() ..yes, i understand what you're talking about. I've taken a year worth of Java classes a while back. A lot of extra code, and a lot more functionality. It's finding the correct way to do the code that can be tough. I've only just begun using VB.NET.. Quote
Administrators PlausiblyDamp Posted February 10, 2004 Administrators Posted February 10, 2004 You get the error running the project as included in the zip file? Works fine for myself..... If you mean in your own project could you post the relevant code? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jazzynites Posted February 25, 2004 Posted February 25, 2004 Multi Forms I'm learning VB.NET. My instructor taught us how to handle the implementation of multiple forms as shown below. The problem of a "Null" form happens when you try to reference the parent from the child, because the child doesn't even know the parent exists. The parent "Form1" is a special Start-Up forrm so you need to make it known to the child. You have to create a reference back to the Parent. There is another way to do this by creating a module and "running" the main form. 'psuedocode... Using multiple forms when hiding the Startup form Button on Parent form loads the Child form and hides itself. Button on Child form loads the Parent and hides itself. References to each other are established so that the Parent from isn�t lost. * parentform.Close terminates the Application. �PARENT FORM Class parentForm '------------------------------------------------------------- Sub btnLoadChild( �) Handles Click Dim childFrmObj as childForm = New childForm childFrmObj.loadParnent(Me) �pass the child a ref childFrmObj.Show() Me.Hide() End Sub �CHILD FORM Class childForm Private parentFrmObj as parentForm '--------------------------------------------------------------- Public Sub loadParent(ByRef f1 as ParentForm) parentFrmObj = f1 End Sub --------------------------------------------------------------- Sub btnShowParent( �) Handles Click parentFrmObj.Show() Me.Hide() End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.