PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] save and rotate a variable grid..-VBForums
Results 1 to 8 of 8

Thread: [RESOLVED] save and rotate a variable grid..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Posts
    93

    Resolved [RESOLVED] save and rotate a variable grid..

    i'm trying to find a good way of storing information in a variable and an easy way to "rotate" it (for lack of a better term).

    the general purposes.. think of the data grid i'm dealing with as a chess board. i need to store strings in that pattern, and i also need a way to rotate that grid 180deg (again much like a chessboard viewed from the other side).

    so far all I've come up with is a list of lists, but i'm hoping there is a more elegant solution..?

    TIA

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,664

    Re: save and rotate a variable grid..

    Are you talking about rotation as something the user will see or just conceptually? If it's the latter then why is it even necessary? The cells of the grid are still what they are. Just index from the max values instead of the min, e.g. for a 10x10 grid, (0,0) is bottom left for one player and (9,9) is bottom left for the other.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Posts
    93

    Re: save and rotate a variable grid..

    Yes this is not for user display, so that would work..

    But what to use for the actual data? Is there a grid variable ?

    Or i suppose a better question would be.. cana custom grid variable be created?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,664

    Re: save and rotate a variable grid..

    For a genuine matrix you would generally use a multidimensional array. For something like a chess board, a 2D array would suit perfectly. Just like a regular 1D array, the type depends on what you want to store. If you wanted to store instances of a ChessPiece class:
    vb.net Code:
    1. Dim board(7, 7) As ChessPiece
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Posts
    93

    Re: save and rotate a variable grid..

    Thanks, that was the piece I was missing.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Posts
    93

    Re: save and rotate a variable grid..

    Quote Originally Posted by jmcilhinney View Post
    For a genuine matrix you would generally use a multidimensional array. For something like a chess board, a 2D array would suit perfectly. Just like a regular 1D array, the type depends on what you want to store. If you wanted to store instances of a ChessPiece class:
    vb.net Code:
    1. Dim board(7, 7) As ChessPiece
    Small problem. When i try to do this in a class..
    Code:
           Public Property Side1(5,5) As TileMove
                Get
                    Return m_Side1
                End Get
                Set
                    m_Side1 = Value
                End Set
            End Property
            Private Property m_Side1(5, 5) As TileMove
    It gives me an error "Auto-implemented properties cannot have parameters.

    Is there another way to do this?? (Full Descl. I don't know much about custom classes).

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,664

    Re: [RESOLVED] save and rotate a variable grid..

    That code is wrong for a number of reasons. Firstly, you have declared two properties instead of a field and a property. Notice how both declarations have the Property keyword in them? This:
    vb.net Code:
    1. Private Property m_Side1(5, 5) As TileMove
    should be a field, not a property:
    vb.net Code:
    1. Private m_Side1(5, 5) As TileMove
    Note that that code is actually a shorthand for this:
    vb.net Code:
    1. Private m_Side1 As TileMove(,) = New TileMove(5, 5) {}
    As you can see from that, the actual type of the field is TileMove(,). That's a 2D array of TileMove. There's no size in the type. The size is only used to create an instance of that type. As such, that's the type you need to declare your property as:
    vb.net Code:
    1. Public Property Side1 As TileMove(,)
    2.     Get
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2016
    Posts
    93

    Re: [RESOLVED] save and rotate a variable grid..

    Quote Originally Posted by jmcilhinney View Post
    This:
    vb.net Code:
    1. Private Property m_Side1(5, 5) As TileMove
    should be a field, not a property:
    vb.net Code:
    1. Private m_Side1(5, 5) As TileMove
    Thank you for pointing that out. That matches all the other classes I have, I'm not sure how it was changed to a property.

    And thank you for the array notes, that cleared it up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width