Object Array Bug

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Adams

    #1

    Object Array Bug

    I have my class which I want to make a two-dimensional array of.

    Public Class SpaceTile
    Public Shared TileType As Integer
    Public Shared Planet As Integer
    Public Shared Occupied As Integer
    Public Shared PosX As Integer
    Public Shared PosY As Integer
    End Class

    Public STiles(100,100) As SpaceTile

    I initialize each with a loop and:
    STiles(x, y) = New SpaceTile

    STiles(ctrX, ctrY).TileType = Val(MyLineParts (0))
    STiles(ctrX, ctrY).Planet = Val(MyLineParts (1))
    STiles(ctrX, ctrY).Occupied = Val(MyLineParts (2))
    STiles(ctrX, ctrY).PosX = Val(MyLineParts (3))
    STiles(ctrX, ctrY).PosY = Val(MyLineParts (4))

    Problem is, it makes all array positions the same. Whenever it makes a new
    entry, it and all previous ones are made the same. Anybody have any ideas
    here? Thanks!


  • J French

    #2
    Re: Object Array Bug

    On Sat, 06 May 2006 00:27:16 GMT, "Mike Adams" <genz44@earthli nk.net>
    wrote:
    [color=blue]
    >I have my class which I want to make a two-dimensional array of.
    >
    >Public Class SpaceTile
    > Public Shared TileType As Integer
    > Public Shared Planet As Integer
    > Public Shared Occupied As Integer
    > Public Shared PosX As Integer
    > Public Shared PosY As Integer
    >End Class[/color]
    [color=blue]
    >Public STiles(100,100) As SpaceTile[/color]
    [color=blue]
    >I initialize each with a loop and:
    >STiles(x, y) = New SpaceTile[/color]

    Set STiles(x, y) = New SpaceTile

    I don't think this is your real code
    [color=blue]
    >STiles(ctrX, ctrY).TileType = Val(MyLineParts (0))
    >STiles(ctrX, ctrY).Planet = Val(MyLineParts (1))
    >STiles(ctrX, ctrY).Occupied = Val(MyLineParts (2))
    >STiles(ctrX, ctrY).PosX = Val(MyLineParts (3))
    >STiles(ctrX, ctrY).PosY = Val(MyLineParts (4))[/color]

    [color=blue]
    >Problem is, it makes all array positions the same. Whenever it makes a new
    >entry, it and all previous ones are made the same. Anybody have any ideas
    >here? Thanks![/color]

    It looks as if you have an Array of 'Object References' all pointing
    to the same Instance


    Comment

    • Steve Gerrard

      #3
      Re: Object Array Bug


      "J French" <erewhon@nowher e.uk> wrote in message
      news:445c4fb6.4 31364077@news.b topenworld.com. ..[color=blue]
      > On Sat, 06 May 2006 00:27:16 GMT, "Mike Adams" <genz44@earthli nk.net>
      > wrote:
      >[color=green]
      >>I have my class which I want to make a two-dimensional array of.
      >>
      >>Public Class SpaceTile
      >> Public Shared TileType As Integer
      >> Public Shared Planet As Integer
      >> Public Shared Occupied As Integer
      >> Public Shared PosX As Integer
      >> Public Shared PosY As Integer
      >>End Class[/color]
      >[color=green]
      >>Public STiles(100,100) As SpaceTile[/color]
      >[color=green]
      >>I initialize each with a loop and:
      >>STiles(x, y) = New SpaceTile[/color]
      >
      > Set STiles(x, y) = New SpaceTile
      >
      > I don't think this is your real code
      >[/color]

      I think the Shared keyword, and the inline class definition, indicate a VB.Net
      app, where Set is not needed.


      Comment

      • J French

        #4
        Re: Object Array Bug

        On Sat, 6 May 2006 10:51:45 -0700, "Steve Gerrard"
        <mynamehere@com cast.net> wrote:
        [color=blue]
        >
        >"J French" <erewhon@nowher e.uk> wrote in message
        >news:445c4fb6. 431364077@news. btopenworld.com ...[color=green]
        >> On Sat, 06 May 2006 00:27:16 GMT, "Mike Adams" <genz44@earthli nk.net>
        >> wrote:
        >>[color=darkred]
        >>>I have my class which I want to make a two-dimensional array of.[/color][/color][/color]
        [color=blue][color=green][color=darkred]
        >>>Public Class SpaceTile
        >>> Public Shared TileType As Integer
        >>> Public Shared Planet As Integer
        >>> Public Shared Occupied As Integer
        >>> Public Shared PosX As Integer
        >>> Public Shared PosY As Integer
        >>>End Class[/color][/color][/color]
        [color=blue][color=green][color=darkred]
        >>>Public STiles(100,100) As SpaceTile[/color][/color][/color]
        [color=blue][color=green][color=darkred]
        >>>I initialize each with a loop and:
        >>>STiles(x, y) = New SpaceTile[/color][/color][/color]
        [color=blue][color=green]
        >> Set STiles(x, y) = New SpaceTile[/color][/color]
        [color=blue][color=green]
        >> I don't think this is your real code[/color][/color]

        [color=blue]
        >I think the Shared keyword, and the inline class definition, indicate a VB.Net
        >app, where Set is not needed.[/color]

        Ah, thanks - I did not spot that

        Comment

        Working...