|
-
Apr 14th, 2003, 04:10 AM
#1
Thread Starter
Member
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.......
-
Apr 14th, 2003, 07:49 PM
#2
Thread Starter
Member
Help....
-
Apr 14th, 2003, 10:50 PM
#3
PowerPoster
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:
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 InfoMins() As Byte
Public InfoSecs() As Byte
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 tmp2 As PROGRAM_TYPE
ReDim tmp2.InfoMins(5)
ReDim tmp2.InfoSecs(5)
tmp.ProgramInformation(0).Programs = 1
tmp.ProgramInformation(0).Number = 1
tmp.ProgramInformation(0).Time.Minutes = 4
tmp.ProgramInformation(2).InfoMins(1) = 23
tmp.ProgramInformation(2).InfoSecs(1) = 23 ' << ALWAYS ERRORS
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.

-
Apr 16th, 2003, 09:56 AM
#4
Lively Member
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.
-
Apr 16th, 2003, 09:57 AM
#5
PowerPoster
I agree, classes are better used in this senerio.
-
Apr 16th, 2003, 10:55 AM
#6
Lively Member
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.
-
Apr 16th, 2003, 07:14 PM
#7
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|