Accessing a MDIChild's variables

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
 
J

joecool1969

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
 
A

Armin Zingler

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
 
R

Rob W

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
 
R

Rob W

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
 

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