Welcome! Log In Create A New Profile

Advanced

How to access elements of multi dimension array

Posted by DW 
Hello All

I trying to work with a structure and am try to figure iut home to access data form it.
//clCabinets is a class that hold the structure
dsD is array of clCabinets

dsD = gclCabinets.arrST_Cabinets
//After call there are 12 dimensions with 10 rows.


how would i get dat from 3 dimension row 1
sItem is string = dsD???

If I try
sItem is string = dsD[1,3]
it gives error:
Array with one dimension(s):unable to access it with 2 dimensions.


Thanks
DW
You have a one dimensional array holding clCabinets. So the only way to retrieve data from your array is using one dimension : dsD[x], where x is the clCabinet you need.

After that you have a clCabinet structure and you can acces its element.
What you are trying to do now is looking at it as a total picture, being a multi dimensional array. Thats wrong.

You did not give us your structure, but say it's looking like this:
clCabinet is structure
{
nID is int
sName is string
}

Then you can do this
sItem is clCabinet
sItem = dsD[1]
Info(sItem.nID,sItem.sName)

Or in one call
Info(gclCabinets.arrST_Cabinets[1].nID, gclCabinets.arrST_Cabinets[1].sName)
Thanks Al

The structure is in a class called clCabinets.


stCabinet is structure
	//These fields will by sent back and forth from the table

	ItemNumber is real
	Nomenclature is string
	QTY is real
	Hinge is string
	FE is string
	Description is string
END

clCabinets is class
	arrST_Cabinets is array of stCabinet
	arrST_Mods is array of  stMods
END

//This is the code that worked.
//Declare the array of structure
arrCabs is array of clCabinets.stCabinet   
 
//Fill it from the class holding the data
//p_arrST_Cabinets is a property of the class with 2 procedures for getting and setting of the data in the class.
arrCabs = gclCabinets.p_arrST_Cabinets

//Declare a single structure to fill each row
//The only reason I do this is the autocomplete works when type the field names
Cab is clCabinets.stCabinet

//Get the number of rows from the array so I can loop thru it to fill my table
nCount is int = ArrayCount(dsD)

For i = 1 to nCount
        Cab = arrCabs
	TableAddLine(TVT_Mods,Cab.ItemNumber,Cab.Nomenclature)
End

//Where I went wrong is delcaring the whole class.
arrCabs is array of clCabinets
//When I should have been doing just the structure that I needed:
arrCabs is array of clCabinets.stCabinet

Thanks again Al you were able to point me in the right direction with little info.

DW
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: