Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
3
Erster Beitrag:
vor 6 Jahren, 2 Monaten
Letzter Beitrag:
vor 6 Jahren, 2 Monaten
Beteiligte Autoren:
DW, Arie

How to access elements of multi dimension array

Startbeitrag von DW am 25.05.2012 00:39

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

Antworten:

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)

von Arie - am 25.05.2012 07:29
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

von DW - am 25.05.2012 13:04
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.