1. ## XY Coordinates

Hi, I'm new to Visual Basic (since this week), and I have encountered my first problem...
I'm trying to display a grid of pictures in a 6 by 7 pattern, so 6 rows, 7 columns :

Dim TheGrid(6, 7) as PictureBox
Dim Row as short
Dim Col as short

For Row = 1 To 6
For Column = 1 To 7
TheGrid(Row, Column) = New PictureBox
TheGrid(Row, Column).Name = "Cell" + Trim(Str(Row)) + "_" + Trim(Str(Column))
TheGrid(Row, Column).BackgroundImage = My.Resources.emptycell

TheGrid(Row, Column).Location = New Point(10 + (50 * Row), 10 + (50 * Column))
TheGrid(Row, Column).Size = New Size(40, 40)
TheGrid(Row, Column).Visible = True
TheGrid(Row, Column).Tag = 0

Next Column
Next Row

Somehow, the result of my sourcecode is a 7 (rows) by 6 (columns) pattern...and I don't know why.
I do have to specify the coordinates as X (row), Y (column) right..?
I know VB starts array indexes from 0, but I'm starting at 1. But that can't be the problem.

What am I doing wrong here?
Tnx

2. ## Re: XY Coordinates

Coordinates are goofy things, it's important to understand what each word means.

On the monitor (and in Cartesian coordinates), the X axis is horizontal, with 0 at the left edge and increasing to the right. That means the X axis represents "columns".

On the monitor the Y axis is vertical, with 0 at the top edge and increasing to the bottom. (This is inverted from standard Cartesian coordinates.) That means the Y axis represents "rows".

You're treating rows as X coordinates and columns as Y coordinates, which will cause them to be transposed.

In Visual Basic, arrays are defined by the upper bounds of their rank, not the size. So your (6, 7) array actually has 7 rows and 8 columns. You should define it as (5, 6), that's a 6 row, 7 column array.

3. ## Re: XY Coordinates

Thanks a lot!
I switched places for the Row and Column in the Location property and indeed...now it works...

#### 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