|
-
Feb 5th, 2007, 10:41 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2005] New List and Declaring Arrays
I'm getting an error about object not being set to an instance of an object. I know it has something to do with the New keyword and when it goes to add data to the list it needs to have the space for it but I don't know what the format is to do that. Can someone point it out?
VB Code:
Public Class dataStructure
Structure VideoEyeAnalysis
Dim second_Stamp As List(Of Integer)
Dim micro_SecondStamp As List(Of Integer)
Dim x_coOrdinates As List(Of Single)
Dim y_coOrdinates As List(Of Single)
Dim leftEye_Validity As List(Of Integer)
Dim rightEye_Validity As List(Of Integer)
Dim distance_measure As List(Of Single)
End Structure
End Class
'24 = trials, 1 = 0 or 1 (number of times the clip is played)
Public VideoEyeData(24, 1) As dataStructure.videoEyeAnalysis 'declare
'On collecting data event I add data like so but this is wrong- how do I use the New word here to create the data point:
VideoEyeData(trial_Count, videoPlay_Count).x_coOrdinates.Add _ 'New have to go here?
((gazeData.GazePosXLeftEye + gazeData.GazePosXRightEye) / 2)
Last edited by stimbo; Feb 5th, 2007 at 10:46 AM.
-
Feb 5th, 2007, 10:48 AM
#2
Fanatic Member
Re: [2005] New List and Declaring Arrays
Why are you declaring a structure? Why not just have a class with a bunch of properties?
Anyway, I would assume it is because you didn't declare those variables as New in the structure.
-
Feb 5th, 2007, 10:54 AM
#3
Re: [2005] New List and Declaring Arrays
Like so (I would guess ):
Dim x_coOrdinates As New List(Of Single)
-
Feb 5th, 2007, 11:13 AM
#4
Thread Starter
Frenzied Member
Re: [2005] New List and Declaring Arrays
I did try doing that to begin with but kept getting an error message so presumed it wasn't correct. The error message was:
"Non-shared members in a Structure cannot be declared 'New'"
I looked this error up on MSDN but couldn't understand the solution.
Remove either the Shared modifier or the New keyword from the reference variable declaration.
-
Feb 5th, 2007, 11:19 AM
#5
Thread Starter
Frenzied Member
Re: [2005] New List and Declaring Arrays
If I place something like:
Public Shared second_Stamp As New List(Of Integer)
I get warnings on the code about:
Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
-
Feb 5th, 2007, 11:22 AM
#6
Fanatic Member
Re: [2005] New List and Declaring Arrays
Does this work?
Public VideoEyeData(24, 1) As New dataStructure.videoEyeAnalysis
instead of
Public VideoEyeData(24, 1) As dataStructure.videoEyeAnalysis
-
Feb 5th, 2007, 11:32 AM
#7
Thread Starter
Frenzied Member
Re: [2005] New List and Declaring Arrays
VB Code:
Arrays cannot be declared with New
No, it doesn't work.
The reason for the structure is that there are more of them within that class. I just included one. They are all so similar (the data collected/variables declared) so I did put them within that one class. Although I haven't done this before so there's no justification for it. Just inexperience.
I'll create a new class just for that data and list its properties and try it from there.
-
Feb 5th, 2007, 11:39 AM
#8
Fanatic Member
Re: [2005] New List and Declaring Arrays
Heh, well, don't forget that you can also declare multiple classes in the same file as well.
-
Feb 5th, 2007, 12:23 PM
#9
Re: [2005] New List and Declaring Arrays
Sorry, I wasn't looking correctly. You dont need to New the structure, but you do need to new the Lists. To do this you will have to loop through (on load or something) each part of the array and create a new one for each:
ie
VB Code:
For intIndex as Integer = 0 to 2
For intInner as Integer = 0 to 24
With VideoEyeData(intInner, intIndex)
.second_Stamp = New List(Of Integer)
.micro_SecondStamp = New List(Of Integer)
.x_coOrdinates = New List(Of Single)
.y_coOrdinates = New List(Of Single)
.leftEye_Validity = New List(Of Integer)
.rightEye_Validity = New List(Of Integer)
.distance_measure = New List(Of Integer)
End With
Next
Next
PS: It might just be "= New List". I'm not using 2005.
PPS: Didnt check that works .
-
Feb 5th, 2007, 01:44 PM
#10
Fanatic Member
Re: [2005] New List and Declaring Arrays
Ah, yeah. Heh, that's what I mean when I said New! Guess I should have clarrified a bit more.
-
Feb 5th, 2007, 03:27 PM
#11
Thread Starter
Frenzied Member
Re: [2005] New List and Declaring Arrays
I got it to work by doing something like this (don't have program at moment but you get the idea):
VideoEyeData(trial_Count, clip_count) = New DataStructure.Whatever
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
|