Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doubly Indexed Control Arrays ?? 1

Status
Not open for further replies.

NeilFrank

Programmer
Joined
Mar 12, 2000
Messages
167
Location
CA

Has anyone figured out how to set up a group of controls that are indexed using 2 subscripts, instead of the usual 1?

For example, I would like to have a 2-D Array of Image controls named imgFoo(1,1), imgFoo(1,2), imgFoo(2,1), etc.

Thanks and have yourself a nice Thanksgiving.

\Frank



 
I have not seen this done anywhere - and not sure if it can be done.

However, when I have wanted to achieve this, I have just concatonated the two index, so I have indexes 11, 12, 13, 21, 22, 23, 31, 32, 33 for a 3 by 3 matrix of text boxes. It requires a little extra work to parse the index value, but not too difficult to achieve desired effect.

Simon
 

Thanks, Simon. Brilliant!

Frank

 
An alternative approach would be to add two functions to the form module -> one function will convert a 1-D index into a row and column number:

'********** Code Start

dim intRows as Integer ' No of rows in grid
dim intCols as Integer ' No of columns in grid

Private Function Index2BoltPlate(ByVal intIndex As Integer) As Variant
End Function
Dim intRow As Integer
Dim intCol As Integer

intRow = (intIndex Mod intRows) + 1
intCol = (intIndex - intRow + 1) / intRows + 1

Index2RC = Array(intRow, intCol)
End Function

Private Function BoltPlate2Index(ByVal intRow As Integer, ByVal intCol As Integer) As Integer

RC2Index = (intCol - 1) * (intRows) + (intRow - 1)
End Function

'*********** Code End

(I have used intRows and intCols as module level variables specifying the number of rows and columns in the grid. This returns a 1-based array index.

So now, you will be able to use imgFoo(RC2Index(1,1)), and conversely in a click event (eg) that takes Index as an argument...

RowCol = Index2RC(Index)
msgbox "This is imgFoo(" & RowCol(0) & "," & rowcol(1) & ")"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top