how to set set var to current instance of object?

A

Adda

Is it possible to set a variable to a current instance of
a running object without using the New keyword?

Here is my situation. I have been trying to add a record
to a dataset on a Parent Mdi form and refresh a datagrid
on this parent at the same time from a childform. I could
not make this happen. The only way I could refresh the
parent form/datagrid was to reset the datagrid datasource
from within the parent. Then I determined that I was
instantiating a New copy of the parent form because I was
using the New keyword in the childform. So I created a
global Form variable in a Module. Essentially, I want to
bridge the parent and childform (is that called
marshalling?). So when the childform is created it is
automatically bridged to the current instance of the
parent form. Is this possible? If so, what is the
correct syntax?

TIA
Adda
 
K

Ken Tucker [MVP]

Hi,

Dim frm as Form1 = Me.MdiParent. Replace form1 with the name of
your mdi parents name.

Ken
 
A

adda

I figured it out! For everyone who has been helping me on
this, that was painful! :). I instantiate a New
Parentform variable in Sub Main. Then I can use that in
the children forms!.

Adda
 
A

Adda

Thank you. This is even better because now I don't need
sub Main(). I suppose the hardest part of this project
was trying to communicate what I needed/was looking for.

Many thanks for your help.
Adda
 
H

Herfried K. Wagner [MVP]

* "Ken Tucker said:
Dim frm as Form1 = Me.MdiParent. Replace form1 with the name of
your mdi parents name.

With 'Option Strict On':

\\\
Dim frm As Form1 = DirectCast(Me.MdiParent, Form1)
///

:)
 
A

Adda

Thank you. Yes, I had to deal with that. I am using
Option String On. I am starting to get the idea about
VB.Net syntax.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top