What replaces "Directcast(me.mdiparent.activemdichild, TypeOfChildForm).txtEdit"

E

Elmo Watson

In VB6, I used :
frmMain.ActiveForm.txtEdit.....whatever

However, I'm using VS.Net 2005 now - - then, I was told to use
Directcast(me.mdiparent.activemdichild, TypeOfChildForm).txtEdit

But when I try to do that, I get an error message with no corrections
suggested:
'TypeOfChildForm' not declared....

I need to globally refer to the txtEdit rich text box (both in frmMain,
which is a MDI container, and in Modules, classes)
How can I accomplish this with DotNet 2.0?
 
E

Elmo Watson

Thanks, I do understand, but, unfortunately, I get an error that 'ChildForm'
is not defined...
 
E

Elmo Watson

Never mind - -
I must be asleep
I changed 'ChildForm' to the name of the form directly (frmEdit) and it
seems to work
 
T

Tim Wilson

Is "ChildForm" the name of a class, that inherits directly or indirectly
from the Form class, that is visible within the current namespace?
 
T

Tim Wilson

Yes. You need to specify the name of the type to cast to. In this case the
name of the type is "frmEdit". So "ChildForm" was not the name of a class
that was defined.
 
E

Elmo Watson

However, I find this won't work in a module:
I made the sub global/public
Public Sub (whatever)
With DirectCast(frmMain.MdiParent.ActiveMdiChild, frmEdit).txtEdit

frmMain is the MDIParent
frmEdit is the ChildForm
txtEdit is the control

It stops on that line and gave me an error:
Object Reference not set to an Object Instance
Use the New keyword to create the instance

Like I've said earlier, having programmed with VB6 for years, this is giving
me fits - - I much prefer the old :
frmMain.ActiveForm.txtEdit syntax - -

How do I get out of this?
 
E

Elmo Watson

DirectCast(Me.MdiParent.ActiveMdiChild, ChildForm).txtEdit
becomes:
DirectCast(Me.ActiveMdiChild, ChildForm).txtEdit
or, in a Module:
DirectCast(frmMain.ActiveMdiChild, ChildForm).txtEdit

and it works - - FINALLY
 

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