views:

55

answers:

1

Hello, I have a dialog in vb6 which changes the values being displayed in its parent dialog.

the x1 is displayed in txt_c1 text in parent dialog and it has a txt_1validate funtion too for the text box. Now i want to change the value of txt_c1 txtbox from child dialog and then call its validate function. But the problem is that txt_c1 is not avaible in child dialog.

Please note that i am working in vb6 in the MS VB 6.0 IDE

+1  A: 

Forms are just classes and can therefore be instantiated explictly (and you will probably find your life easier if you do rather than using the automatic instantiation in VB6) and references to forms can be assigned.

You can solve your problem by creating a public property on your child dialog (Form1.frm) of type Form that you set to the instance of the parent dialog thus giving you access to the controls andd methods on the parent from the child.

My VB6 is somewhat rusty (and I don't have an installed instance available) so this isn't going to be actual, correct code - but something along the lines of the following should work

In the code that calls the child:

Form childDialog = new Form1
childDialog.Parent = this
childDialog.ShowModal

Then in the child dialog:

Parent.txt_c1 = newValue
if not Parent.Validate then
...
end if
Murph
Not a bad try at VB6, I'm guessing you've moved to C#? I think you mean something like `Dim childDialog As Form1: Set childDialog = New Form1: Set childDialog.Parent = Me: childDialog.Parent.Show vbModal` and then `Parent.txt_c1.Text = newValue: If Not Parent.Validate Then` I would also guess that jaminator may need to make `txt_1validate` Public
MarkJ
Murph thanks for your answer, my chilad dialogs name is attachmentsFrm and when i try to do Form instance = New attachmentsFrm it is giving error
jaminator
yup its working thanks Mark and Murph
jaminator
@MarkJ yup - probably 8 years now since I did VB.OLD in any meaningful sense.
Murph