Results 1 to 7 of 7

Thread: Structures.... Got A Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53

    Structures.... Got A Problem

    Code:
      Public Structure ROO_1
        Public Minutes As Byte
        Public Seconds As Byte
      End Structure
    
      Public Structure INFO_TYPE
        Public SetInfo As Integer
        Public BackTime As ROO_1
      End Structure
    
      Public Structure PROGRAM_TYPE
        Public Programs As Byte
        Public Number As Byte
        Public Time As ROO_1
        Public Information() As INFO_TYPE
      End Structure
    
      Public Structure MY_MAIN_TYPE
        Public Filename As String
        Public ProgramInformation() As PROGRAM_TYPE
      End Structure
    
      Public Function TestFunc() As MY_MAIN_TYPE
    
        Dim tmp As MY_MAIN_TYPE : ReDim tmp.ProgramInformation(16)
        Dim tmp_two As PROGRAM_TYPE : ReDim tmp_two.Information(8)
        'ALSO TRIED THIS >> ReDim tmp.ProgramInformation(16).Information(8)
    
        tmp.ProgramInformation(0).Programs = 1
        tmp.ProgramInformation(0).Number = 1
        tmp.ProgramInformation(0).Time.Minutes = 4
        tmp.ProgramInformation(2).Information(2).BackTime.Seconds = 43 ' << ALWAYS ERRORS
    
        Return tmp
      End Function
    Sorry for all the code but this is to give you an idea of my problem.
    I always get an instance/object error. I've use 'redim' on ProgramInformation as I want it (16), a set size, but I can't seemed to find a way to do it to 'Information' in the program_type structure, obviously something to do with it being a structure in a structure no doubt, how do I get around this? I VB6 I could just declare the size/arraysize in the structure.

    I've also tried the <VBFixedArray(8)> method, no luck.

    Please Help.......

  2. #2

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53


    Help....

  3. #3
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Well what you're trying to do will not work. I tried changing Information to a multi dementional array but you cant declare an array inside a structure soo that wont work either. The only other options is to create 2 info arrays one for mins and secs. Ofcourse this mean you'll have to restructure your entire concept.


    Basically something like this, but ROO will have to be changed or deleted as its not part of Information any more.

    VB Code:
    1. Public Structure ROO_1
    2.         Public Minutes As Byte
    3.         Public Seconds As Byte
    4.     End Structure
    5.  
    6.     Public Structure INFO_TYPE
    7.         Public SetInfo As Integer
    8.         Public BackTime As ROO_1
    9.     End Structure
    10.  
    11.     Public Structure PROGRAM_TYPE
    12.         Public Programs As Byte
    13.         Public Number As Byte
    14.         Public Time As ROO_1
    15.         Public InfoMins() As Byte
    16.         Public InfoSecs() As Byte
    17.     End Structure
    18.  
    19.     Public Structure MY_MAIN_TYPE
    20.         Public Filename As String
    21.         Public ProgramInformation() As PROGRAM_TYPE
    22.     End Structure
    23.  
    24.     Public Function TestFunc() As MY_MAIN_TYPE
    25.  
    26.         Dim tmp As MY_MAIN_TYPE
    27.         ReDim tmp.ProgramInformation(16)
    28.         Dim tmp2 As PROGRAM_TYPE
    29.         ReDim tmp2.InfoMins(5)
    30.         ReDim tmp2.InfoSecs(5)
    31.  
    32.  
    33.  
    34.         tmp.ProgramInformation(0).Programs = 1
    35.         tmp.ProgramInformation(0).Number = 1
    36.         tmp.ProgramInformation(0).Time.Minutes = 4
    37.         tmp.ProgramInformation(2).InfoMins(1) = 23
    38.         tmp.ProgramInformation(2).InfoSecs(1) = 23 ' << ALWAYS ERRORS
    39.  
    40.         Return tmp
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  4. #4
    Lively Member
    Join Date
    Feb 2003
    Location
    UK
    Posts
    95
    If you are using VB.NET I would strongly recommend that you learn the basics of OOP. The use of Classes instead of structures would illimiate your problems. Each class could then manage itself as you can put your 'structure' specific code within itself.

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I agree, classes are better used in this senerio.

  6. #6
    Lively Member
    Join Date
    Feb 2003
    Location
    UK
    Posts
    95
    I've knocked up a (very) noddy console app to mirror your code snippet using classes.

    it's a little large to post so email me if you want a copy.

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    Cheers, I've sent you an email.

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