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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing array values using an index

Status
Not open for further replies.

neiljabba

IS-IT--Management
May 22, 2003
86
GB
Hello all

This probably sounds really dumb but how do I search thorugh a 2D array looking for a value and getting it to return the value connected to it.

Eg 7.1,1
7.2,2

where I am looking using 7.1 as the index and returning 1 as the value

I am comfortable with loops etc and assume that that is my method but....


many thanks in advance

Neil
 
to reference a 2d array, just use
myVal = myArray(1,2)
or sub a variable in:
myVal = myArray(r,c)

Rgds, Geoff
Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
Want the best answers to your questions ? faq222-2244
 
Hi neiljabba,

You can't reference an array by the contents like that, you use a numeric index and check the contents, so assuming your array is called yourArray ..

Code:
Dim i As Integer
For i = LBound(yourArray) To UBound(yourArray)
If yourArray(i, LBound(yourArray, 2)) = 7.1 Then
    Msgbox yourArray(i, UBound(yourArray, 2)) 
End If
Next

You can make it a bit simpler if you substitute your actual values for the generic LBounds/UBounds.

Enjoy,
Tony
 
how do

cheers folks Ill try them out

many thanks again

Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top