Results 1 to 11 of 11

Thread: [RESOLVED] [2005] New List and Declaring Arrays

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Resolved [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:
    1. Public Class dataStructure
    2.  
    3.     Structure VideoEyeAnalysis
    4.         Dim second_Stamp As List(Of Integer)
    5.         Dim micro_SecondStamp As List(Of Integer)
    6.         Dim x_coOrdinates As List(Of Single)
    7.         Dim y_coOrdinates As List(Of Single)
    8.         Dim leftEye_Validity As List(Of Integer)
    9.         Dim rightEye_Validity As List(Of Integer)
    10.         Dim distance_measure As List(Of Single)
    11.     End Structure
    12.  
    13. End Class
    14. '24 = trials, 1 = 0 or 1 (number of times the clip is played)
    15. Public VideoEyeData(24, 1) As dataStructure.videoEyeAnalysis  'declare
    16.  
    17. '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:
    18.  
    19.  VideoEyeData(trial_Count, videoPlay_Count).x_coOrdinates.Add _  'New have to go here?
    20.         ((gazeData.GazePosXLeftEye + gazeData.GazePosXRightEye) / 2)
    Last edited by stimbo; Feb 5th, 2007 at 10:46 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  2. #2
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    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.

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: [2005] New List and Declaring Arrays

    Like so (I would guess ):

    Dim x_coOrdinates As New List(Of Single)

  4. #4

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

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

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  5. #5

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

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

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  6. #6
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    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

  7. #7

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] New List and Declaring Arrays

    VB Code:
    1. 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.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  8. #8
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    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.

  9. #9
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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:
    1. For intIndex as Integer = 0 to 2
    2.   For intInner as Integer = 0 to 24
    3.     With VideoEyeData(intInner, intIndex)
    4.         .second_Stamp = New List(Of Integer)
    5.         .micro_SecondStamp = New List(Of Integer)
    6.         .x_coOrdinates = New List(Of Single)
    7.         .y_coOrdinates = New List(Of Single)
    8.         .leftEye_Validity = New List(Of Integer)
    9.         .rightEye_Validity = New List(Of Integer)
    10.         .distance_measure = New List(Of Integer)      
    11.     End With
    12.   Next
    13. Next

    PS: It might just be "= New List". I'm not using 2005.
    PPS: Didnt check that works .

  10. #10
    Fanatic Member MetalKid's Avatar
    Join Date
    Aug 2005
    Location
    Green Bay, Wisconsin
    Posts
    534

    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.

  11. #11

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    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
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

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