Pass a variable from child form to parent form.
This is a bit complicated.
I have a form called fMain, which most of the action in my program happens.
Then in a function of that form I instance a form called fBeam.
Then in fBeam, I instance a new form called fSection.
How can I pass the user selection in fSection to fBeam?
Thanks
Re: Pass a variable from child form to parent form.
When you say the user selection what exactly are you referring to? If its just something like a selection from a combobox then cant you just reference the fSection.MyComboBox.SelectedItem property from fBeam?
Obviously that example would only work with a combobox but you get the idea
Re: Pass a variable from child form to parent form.
Well, the idea is that a big complicated form creates a new instance of another really complicated form in which the user selects a bunch of options and then closes that new form. The results of which get transfered back to the parent.
Re: Pass a variable from child form to parent form.
Well the same thing still applies, if you everything you want to 'transfer' back to the parent is visual stuff in the controls (e.g change a textbox's text or select a checkbox etc) then you could do this in the click event of your OK button on your fSection form or something similar. All you need to do to set the properties of controls on another form is just put the form instance name before the control name, like so:
vb Code:
fBeam.MyTextBox.Text = MyTextBoxOnAnotherForm.Text
However, if its not all properties of controls that you want to share and you are just wanting to pass variables accross the forms then you have a couple of options. I'm fairly new to doing this kind of thing myself so someone with more experience may be able to give you a better solution but I believe you could either declare the variables as Public (I think this is bad practice though) or you could declare the variables as Shared Properties of the main form... orrr you could create your own object that would store all of these variables and pass that accross the forms. Again, I'm quite new to sharing things properly accross forms so sorry if this isn't that helpful!
Re: Pass a variable from child form to parent form.
The form I'm passing the variables to is an instance. There may be multiple instance of this class. I can't just use the class name now can I?
Re: Pass a variable from child form to parent form.
Well then you could declare the variables as Public in a Module and that way they are accessible to everything all the time... but like I said before, I think this is considered a bad practice and someone with more experience will probably post soon with a better solution :)
Re: Pass a variable from child form to parent form.
You're still not getting it. This is an instance of a class. I can't manipulate the instance of a class based on the class name.
Re: Pass a variable from child form to parent form.
Nevermind, I figured it out for my self. The code looked something like:
Code:
Dim fForm As fSBeam
fForm = Me.Owner
fForm.oBeam = Me.oCalc
oBeam and oCalc are objects that store various bits of information in this calculation.
Re: Pass a variable from child form to parent form.
Quote:
Originally Posted by NewtonsBit
You're still not getting it. This is an instance of a class. I can't manipulate the instance of a class based on the class name.
Declaring a variable as public in a module doesnt require you to use any class names at any point either in the declaration or the usage...
but anyway, as long as you got it sorted then it doesnt matter eh.
Re: Pass a variable from child form to parent form.
Check out this thread. There's an example of what you need in post number 6 http://www.vbforums.com/showthread.p...ighlight=form2
Class properties are preferred as opposed to using publid properties as they follow the OOP paradigm, or methodology of programming.