Assign arrays to MDIchilds and Access from Parent Form
Hello, I'm programming an app with multiple documents, on each document I need an array of variables
but I can't access them form the MDI form (parent)
Example:
On the Child Form at the general declarations section:
Dim XYZ(50) as Integer
On the Parent Form I need to access this variable, I assume I will need to use:
ActiveForm.XYZ(3) = 5000
but this doesn't work,
any ideas how to accomplish this..?
Thanks
Re: Assign arrays to MDIchilds and Access from Parent Form
Welcome to the Forums
:wave:
Make the aray public. eg.
Code:
Puiblic XYZ(50) as Integer
:)
Re: Assign arrays to MDIchilds and Access from Parent Form
Thanks for the welcome and the fast response but I already tried that and i get this error:
compile error --- Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of objects modules.
any other idea?
Re: Assign arrays to MDIchilds and Access from Parent Form
Is this array needed for every Child form?
If so, you can put that in a Module (Bas) and access it.
There also need to make it public.
:wave:
Re: Assign arrays to MDIchilds and Access from Parent Form
Yes I need an array for every child,
I was thinking on doing that with multidimensional arrays, but it has to be an easier way... because its a lot of arrays i need for every form
Re: Assign arrays to MDIchilds and Access from Parent Form
Are these array going to be same for every child?
Meaning,
For Form1 - XYZ array
Form2 - XYZ array
Or Form1- ABC array
Form2 - XYZ Array.
If you want the first method, may be you can create a class or User Defined Type with required variables/arrays and create an array of that UDT or Class.
Re: Assign arrays to MDIchilds and Access from Parent Form
You could create a custom property in your form.
Code:
Private mXYZ(50) as Integer
Public Property Get XYZ(Byval Index as Long) as Integer
If Index >= 0 And Index <=50 Then
XYZ = mXYZ(Index)
Else
Err.Raise -1, "Get XYZ" , "Invalid Index"
End If
End Property
Public Property Let XYZ(Byval Index as Long, ByVal Value As Integer)
If Index >= 0 And Index <=50 Then
mXYZ(Index) = Value
Else
Err.Raise -1, "Let XYZ" , "Invalid Index"
End If
End Property
' in MDIForm
Dim x as integer
ActiveForm.XYZ(3) = 5000
x = ActiveForm.XYZ(24)
Re: Assign arrays to MDIchilds and Access from Parent Form
Thats a good solution. :thumb:
Re: Assign arrays to MDIchilds and Access from Parent Form
zeezee, yes I need on every form the same array,
brucevde,
Thanks, but I also tried the custom property route, but it will be a nightmare because my arrays are not this simple:
In a (bas) module I have
Code:
Type segmento
x1 As Integer
x2 As Integer
y1 As Integer
y2 As Integer
ancho As Integer
id As Integer
layer As Byte
End Type
Type texto
X As Integer
Y As Integer
size As Integer
texto As String
orientacion As Integer
layer As Byte
End Type
...
there are 7 types, every one with on average six values, so i will need to create a Property get and property let for every value on every variable of these types.
any other suggestion anyone?
Re: Assign arrays to MDIchilds and Access from Parent Form
Quote:
Originally Posted by animo3d
there are 7 types, every one with on average six values, so i will need to create a Property get and property let for every value on every variable of these types.
That would be correct. Why would that be a problem?
Re: Assign arrays to MDIchilds and Access from Parent Form
Are these UDTs (user defined types) arrayed or not?
There may be a sophisticated approach using CopyMemory that could significantly reduce the overhead. However, a warning will come with the solution since CopyMemory will be in use.
Re: Assign arrays to MDIchilds and Access from Parent Form
OK if these array will be same, one approach would be to include all the variables required for the Froms into a another type/class, and create an array of that type. Eg.
Code:
Public Type FormData
FormName as String ' or Form Index?
Type1Data() as MyType1
Type2Data() as MyType2
'like this for each aray/variabe
End Type
public MyFormData() as FormData
This might not be the best solution. But something you can do. BTW, are these arrays you want dynamic or static? If dynamic it might not be much easier.
:wave:
Re: Assign arrays to MDIchilds and Access from Parent Form
zeezee, that is a good way to do it thank you,
Lavolpe, the use of CopyMemory sound interesting, I will google a little bit about it, because overhead is a big concern for me...
thanks
Re: Assign arrays to MDIchilds and Access from Parent Form
Are these arrays private for each child and you need to access them from the parent? This sounds overly complicated, perhaps you could explain what you are attempting to accomplish? Maybe a different approach is needed...