2D array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: 2D array

  1. #1
    Join Date
    Apr 2012
    Posts
    3

    2D array

    I have two textbox that user input string into.
    how can i store those two value in 2D array and output,
    Thanks,

  2. #2
    Join Date
    Sep 2011
    Posts
    75

    Re: 2D array

    You are going to have to be more specific but if you are using winapi
    you can acquire the text strings from the message EM_GETLINE i believe. There is plenty of documentation online....
    http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx

    you will have to use EM_GETLINEINDEX (i think) beforehand to get the index of the first character. There are examples available on msdn, once again.

  3. #3
    Join Date
    Apr 2012
    Posts
    3

    Re: 2D array

    Thanks for replying

    this is an example but what i am looking for is for user to enter data instead of
    Assigning Values


    Dim strBooks(4, 1) As String

    strBooks (0, 0) = "Learning Visual Basic"
    strBooks (0, 1) = "John Smith"
    strBooks (1, 0) = "Visual Basic in 1 Week"
    strBooks (1, 1) = "Bill White"
    strBooks (2, 0) = "Everything about Visual Basic"
    strBooks (2, 1) = "Mary Green"
    strBooks (3, 0) = "Programming Made Easy"
    strBooks (3, 1) = "Mark Wilson"
    strBooks (4, 0) = "Visual Basic 101"
    strBooks (4, 1) = "Alan Woods"

  4. #4
    Join Date
    Sep 2011
    Posts
    75

    Re: 2D array

    it also depends on how you are allocating data. so you want a 4x2 array of strings? are you using pointers or STL objects?


    char *stringTable[4][2];
    char userString[256] = {'\0'};
    for(int i = 0; i < 4; i++)
    {
    for(int j = 0; j <2; j++)
    {
    cin>> userString;
    strcpy(stringTable[i][j], userString);
    }
    }

    Should work...

  5. #5
    Join Date
    Apr 2012
    Posts
    3

    Re: 2D array

    I am using VB 2010 and Window Form
    Will this code work ?

  6. #6
    Join Date
    Sep 2011
    Posts
    75

    Re: 2D array

    I don't know anything about those. You are probably posting in the wrong forum as this is the graphics section.

  7. #7
    Join Date
    Feb 2012
    Location
    Fremont,CA
    Posts
    35

    Re: 2D array

    We want to store information about what pieces are in which locations. The most natural way to store it would be to index locations by the row and column. This is easily done with a 2-dimensional array:

    To declare a 2-D array (of primitive types):

    final int BLANK = 0; // location empty
    final int WHITE = 1; // white piece
    final int BLUE = 2; // blue piece

    int board[][] = new int[8][8]; // create 64 integers

    board[0][0] = WHITE; // a white piece in row 0, column 0
    board[0][1] = BLANK; // row 0, column 1 is empty
    board[6][0] = BLUE; // a blue piece in row 6, column 0
    Or use a nested loop to load the entire array full of blanks:

    for (int i=0; i < 8; i++)
    for (int j=0; j < 8; j++)
    board[i][j] = BLANK;
    Make sure you check out my >>Facebook Development Blog and Website<<

  8. #8
    Join Date
    Aug 2012
    Posts
    20

    Re: 2D array

    The above code must work in Visual Basic.
    As "str" is being used for showing "string" in visual basic.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center