Sziasztok!
Tömböt szeretnék használni a BASCOM-ban,
lehetőleg több dimenziósat.
Dim tömb(20)(5) as Byte
Valami ilyesmire gondoltam, de
természetesen ez nem működik.
Köszi: Peti
Több dimenziós tömb
Rossz hírem van. Ez nem működik.
Tipp:
Ez nem jo?
Esetleg berakod function hívásba...
valahogy így:
Tipp:
Kód: Egész kijelölése
$sim
Dim A(5) As Byte
Dim B As Byte
Dim Sor As Byte
Dim Oszlop As Byte
Sor = 0
Oszlop = 0
B = Sor * 5
B = B + Oszlop
B = B + 1
A(b) = 1
Ez nem jo?
Esetleg berakod function hívásba...
valahogy így:
Kód: Egész kijelölése
'--------------------------------------------------------------------------------
Const cArrayD1 = 7 ' define here Size of dimension 1
Const cArrayD2 = 13 ' define here Size of dimension 2
Const cArrayD1D2 = cArrayD1 * cArrayD2 ' sum of elements in 2d-Array
Dim bArray2D(cArrayD1D2) as Byte ' hold the data of the 2d-array
Declare Function GetArray2D (D1 as Byte, D2 as Byte) as Byte
Declare Sub SetArray2D (D1 as Byte, D2 as Byte, pValue as Byte) as Byte
Dim b1 as Byte ' counter for D1
Dim b2 as Byte ' Counter for D2
Dim b3 as Byte ' array value to write and read
b3 = 0
print "Writing a value to each element of the 2d-array"
print "D1 D2 Value"
for b1 = 1 to cArrayD1
for b2 = 1 to cArrayD2
setArray2D b1, b2, b3
print b1; " " ; b2 ; " " ; b3
incr b3
next
next
print "Reading each element of the 2d-array"
print "D1 D2 Value"
for b1 = 1 to cArrayD1
for b2 = 1 to cArrayD2
b3 = GetArray2D(b1, b2)
print b1; " " ; b2 ; " " ; b3
next
next
end
Function GetArray2D (D1 as Byte, D2 as Byte) as Byte
Local WArrayPointer as Word
wArrayPointer = d1 - 1
wArrayPointer = wArrayPointer * cArrayD2
wArrayPointer = wArrayPointer + D2
GetArray2D = bArray2D(wArrayPointer)
end Function
Sub SetArray2D (D1 as Byte, D2 as Byte, pValue as Byte) as Byte
Local WArrayPointer as Word
wArrayPointer = d1 - 1
wArrayPointer = wArrayPointer * cArrayD2
wArrayPointer = wArrayPointer + D2
bArray2D(wArrayPointer) = pValue
end Sub