Accessing a MDIChild's variables

  • Thread starter Thread starter Rob W
  • Start date Start date
R

Rob W

Greetings,

I have a form (MDIChild) with the variable ActiveDocument (see below)

Public Class document

Public ActiveDocument As String

End Class



How can I access this from the MDIParent?

I have tried the following :-

Dim openDocument As document = CType(Me.ActiveMdiChild, document)

openDocument.ActiveDocument ???

Any suggestions?



Thanks

Rob
 
Greetings,

I have a form (MDIChild) with the variable ActiveDocument (see below)

Public Class document

Public ActiveDocument As String

End Class

How can I access this from the MDIParent?

I have tried  the following :-

Dim openDocument As document = CType(Me.ActiveMdiChild, document)

openDocument.ActiveDocument ???

Any suggestions?

First, the "proper .NET" way to expose data is with a property.

Public Class document

Private _ActiveDocument As String

Public Property ActiveDocument As String
Get
Return _ActiveDocument
End Get
Set (ByVal value As String)
_ActiveDocument = value
End Set
End Property

End Class

Then in your parent form:

Dim childForm = CType(Me.ActiveMdiChild, document)
Dim myString As String

myString = childForm.ActiveDocument
 
Rob said:
Greetings,

I have a form (MDIChild) with the variable ActiveDocument (see below)

Public Class document

Public ActiveDocument As String

End Class



How can I access this from the MDIParent?

I have tried the following :-

Dim openDocument As document = CType(Me.ActiveMdiChild, document)

openDocument.ActiveDocument ???

Any suggestions?

That's how I'd do it. What does not work? I tried it and it worked.


Armin
 
I have been reading up on OOP programming and in the main form intended to
write a function to cast the ActiveMdiChild to type document (the sub
form/class). I assume what I'm trying to do is not achievable?

Public Function convertMDI2Document(ByVal currentForm As Form) As document
currentForm = CType(Me.ActiveMdiChild, document)

Return currentForm

End Function



Then access the property as follows:-

MessageBox.Show(convertMDI2Document(Me.ActiveMdiChild).defaultFilename)



I'm struggling as it won't allow me to pass in a value of one type for it to
be returned as another.

I assume what I'm trying to do is not achievable?

Can anyone suggest a way forward?


Greetings,

I have a form (MDIChild) with the variable ActiveDocument (see below)

Public Class document

Public ActiveDocument As String

End Class

How can I access this from the MDIParent?

I have tried the following :-

Dim openDocument As document = CType(Me.ActiveMdiChild, document)

openDocument.ActiveDocument ???

Any suggestions?

First, the "proper .NET" way to expose data is with a property.

Public Class document

Private _ActiveDocument As String

Public Property ActiveDocument As String
Get
Return _ActiveDocument
End Get
Set (ByVal value As String)
_ActiveDocument = value
End Set
End Property

End Class

Then in your parent form:

Dim childForm = CType(Me.ActiveMdiChild, document)
Dim myString As String

myString = childForm.ActiveDocument
 
Ignore, solved.

Public Function convertMDI2Document(ByVal currentForm As Form) As document

Return CType(Me.ActiveMdiChild, document)

End Function



Will learn not to be so hasty in seeking assistance next time!



Thanks all
 
Back
Top