Announcement

Collapse
No announcement yet.

Can a Array contain a TYPE that contains a TYPE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can a Array contain a TYPE that contains a TYPE

    This compiles but is it legal? Does PB know how to do all this?

    TYPE FuncVarType ' TYPE to store the variables
    Pr1 AS SINGLE
    Pn1 AS SINGLE
    Pr2 AS SINGLE
    i as long
    j as long
    END TYPE

    GLOBAL NewVars AS FuncVarType, OldVars AS FuncVarType, BigVars AS FuncVarType

    TYPE WrapperType
    NewVars AS FuncVarType
    OldVars AS FuncVarType
    BigVars AS FuncVarType
    END TYPE

    GLOBAL WrapperArray() AS WrapperType ' Array to store the TYPE

    ------------------
    Kind Regards
    Mike

  • #2
    No problem! You'll get confused long before the compiler will.

    -- Eric

    ------------------
    Perfect Sync Development Tools
    Perfect Sync Web Site
    Contact Us: mailto:[email protected][email protected]</A>
    "Not my circus, not my monkeys."

    Comment


    • #3
      Oops, I read your post wrong the first time. It will compile, and all of the variables and TYPEs will work perfectly, but you would be creating global variables and elements of your TYPE, and I suspect that's not what you meant to do. You don't need this line at all:

      Code:
      GLOBAL NewVars AS FuncVarType, OldVars AS FuncVarType, BigVars AS FuncVarType
      Without that you will be creating a GLOBAL array of "WrapperType"s, each of which will contain the sub-structures you specified. You would access them like this:

      Code:
      spResult = WrapperArray(10).OldVars.Pr2
      -- Eric

      ------------------
      Perfect Sync Development Tools
      Perfect Sync Web Site
      Contact Us: mailto:[email protected][email protected]</A>
      "Not my circus, not my monkeys."

      Comment


      • #4
        he he - coool

        How about this then?

        TYPE FuncVarType ' TYPE to store all the variables we need to carry foreward
        Pr1 AS SINGLE
        Pn1 AS SINGLE
        Pr2 AS SINGLE
        END TYPE

        GLOBAL NewVars AS FuncVarType, OldVars AS FuncVarType ' Instances of the TYPE
        GLOBAL Stack1() AS FuncVarType ' Array to store the TYPE
        GLOBAL Stack2() AS FuncVarType
        GLOBAL Stack3() AS FuncVarType
        GLOBAL Stack4() AS FuncVarType
        GLOBAL Stack5() AS FuncVarType

        TYPE WrapperType ' TYPE to store the TYPE arrays
        Stack1 AS FuncVarType
        Stack2 AS FuncVarType
        Stack3 AS FuncVarType
        Stack4 AS FuncVarType
        Stack5 AS FuncVarType
        END TYPE

        GLOBAL Weights() AS WrapperType ' Array to store ALL the FuncVarType Arrays

        ------------------
        Kind Regards
        Mike

        Comment


        • #5
          Well, Stack1() and Stack1 would not be the same variables. I'm guessing that you are trying to create one large data structure, not two.

          I have never tried creating an array of TYPEs within a TYPE. The docs say that you can create arrays within TYPEs as long as the structures are fixed-size, which TYPEs are, but I have never tried it. I'll try to whip something up and see if it works.

          Even if it doesn't, you could accomplish the same thing by creating a two-dimensional array.

          -- Eric


          ------------------
          Perfect Sync Development Tools
          Perfect Sync Web Site
          Contact Us: mailto:[email protected][email protected]</A>
          "Not my circus, not my monkeys."

          Comment


          • #6
            I should never have doubted that PB could handle it...

            Just for fun I took it one step beyond your question, and it works perfectly.

            Code:
            TYPE Inner
                 lElement1 AS LONG
                 lElement2 AS LONG
            END TYPE
              
            TYPE Middle
                 InnerType(10) AS Inner
            END TYPE
             
            TYPE Outer
                 MiddleType(10) AS Middle
            END TYPE
             
            FUNCTION PBMain AS LONG
             
                 DIM MyStructure(10) AS GLOBAL Outer
             	
                 MyStructure(5).MiddleType(3).InnerType(1).lElement1 = 99
             
                 PRINT MyStructure(5).MiddleType(3).InnerType(1).lElement1
                 WAITKEY$
            
            END FUNCTION
            -- Eric

            ------------------
            Perfect Sync Development Tools
            Perfect Sync Web Site
            Contact Us: mailto:[email protected][email protected]</A>
            "Not my circus, not my monkeys."

            Comment


            • #7
              No problem... you just have more GLOBAL arrays. What exactly do you want to achieve? As Eric says, a multi-dimensional array may be what you are looking for?

              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:lanceedmon[email protected]

              Comment


              • #8
                yeah you guys are right, I need to use a multi dimensional array. I think it would be alot easier.

                thx

                ------------------
                Kind Regards
                Mike

                Comment

                Working...
                X