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

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
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?
 
Thanks, I do understand, but, unfortunately, I get an error that 'ChildForm'
is not defined...
 
Never mind - -
I must be asleep
I changed 'ChildForm' to the name of the form directly (frmEdit) and it
seems to work
 
Is "ChildForm" the name of a class, that inherits directly or indirectly
from the Form class, that is visible within the current namespace?
 
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.
 
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?
 
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
 
Back
Top