Results 1 to 14 of 14

Thread: Assign arrays to MDIchilds and Access from Parent Form

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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

  2. #2
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Assign arrays to MDIchilds and Access from Parent Form

    Welcome to the Forums

    Make the aray public. eg.

    Code:
    Puiblic XYZ(50) as Integer
    IIF(Post.Rate > 0 , , )

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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?

  4. #4
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    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.
    IIF(Post.Rate > 0 , , )

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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

  6. #6
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    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.
    IIF(Post.Rate > 0 , , )

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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)

  8. #8
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Assign arrays to MDIchilds and Access from Parent Form

    Thats a good solution.
    IIF(Post.Rate > 0 , , )

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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?

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.

  12. #12
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    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.
    IIF(Post.Rate > 0 , , )

  13. #13

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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

  14. #14
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width