Results 1 to 6 of 6

Thread: 6.0 -> 2010

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    6.0 -> 2010

    hi

    i was used to be vb 6.0. but now im starting with vb 2010 because 6.0 is old
    but now i have a few problems with converting some things for my game that im making.

    in 6.0 it was

    modPlayer (module)
    Code:
    Public Player(1 To MAX_PLAYERS) as PlayerRec
    
    Private Type PlayerRec
    
    Name as string
    Level as string
    
    End Type
    but this code gives in 2010 some errors; it says it should be structures right now?


    Code:
    Module modPlayerRec
    
        Public Player(0 To 100) As PlayerRec
    
        Structure PlayerRec
    
            Public Name As String
    
        End Structure
    
    End Module
    what should be the right code for vb 2010? this is not working what i have right now..
    thanks in advanced!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,414

    Re: 6.0 -> 2010

    try this:

    vb Code:
    1. Private Structure PlayerRec
    2.     Private Name as string
    3.     Private Level as string
    4. End Structure
    5.  
    6. Public Player(MAX_PLAYERS - 1) as PlayerRec 'arrays are zero based in vb.net

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: 6.0 -> 2010

    Whether the upper bound of the array needs to be 100 is hard to say, that depends on what you had for MAX_PLAYERS, previously. However, you don't need the "0 to" part. All collections in .NET are 0 based, so explicitly stating that fact isn't necessary.

    The Type you had before had two members, but the one you show in the second snippet has only one. What happened to the level?

    As a general practice, it often isn't so good to use Public member variables. It takes a bit more typing, but if you make the member variables private, and expose them via properties, you get a few advantages....which you may not even care about. I sometimes use Public members for some classes, but only very rarely, and only when there is no chance that I will binding or searching them. Since you have an array, both of those are more likely.

    Also, there might be a question whether to use a Structure or a Class, but as you have it, a Structure will work fine.
    My usual boring signature: Nothing

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: 6.0 -> 2010

    I thought I might be taking too long.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: 6.0 -> 2010

    Great I got it working! thanks!

    Code:
        Public Player(0 To 100) As PlayerRec
    
        Public Structure PlayerRec
            Public Name As String
            Public Level As String
        End Structure

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: 6.0 -> 2010

    You still don't need the (0 to 100). You only need the (100), because the "0 to" is automatic.
    My usual boring signature: Nothing

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