For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Controls > January 2006 > 2 dimensional array of text controls









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author 2 dimensional array of text controls
Wowbagger

2006-01-23, 9:57 pm

How would I go about creating a 2 dimensional array of text boxes so that
each box can be referred to by a row, column reference?

Thanks



Rick Rothstein [MVP - Visual Basic]

2006-01-23, 9:57 pm

> How would I go about creating a 2 dimensional array
> of text boxes so that each box can be referred to by
> a row, column reference?


You can't have a two-dimensional control array, but you can simulate one
from a one-dimensional control array. Number the Index values of your
TextBox control array consecutively starting at 0 and moving horizontally up
to the maximum column and then move down to the next row. For the code
procedures that follow, I am assuming the Row and Column values will be
counted from 0 upward. The only thing the routines need to know is the
ColumnCount (although you probably will need to know the RowCount also, for
error checking purposes).

If you know the Row and Column:

ControlArrayIndex = Row * ColumnCount + Column

If you know the control array index:

Row = ControlArrayIndex \ ColumnCount

Column = ControlArrayIndex Mod ColumnCount

Remember, ColumnCount is the number of columns, not the maximum column
index.

Rick


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com