October 31, 2025, 02:27:42 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


data array

Started by yujinwunz, January 23, 2009, 03:04:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

yujinwunz

very quickly, can i define data blocks with arrays? eg.

DATABEGIN mydata[3]
...
DATAEND


thanks
yujin

Parker

No, I don't believe you can. I can't exactly figure out what that statement would do either (would mydata[3] point to the block of data or would it create just a regular array?) - if you explain what you're trying to do we can help you with a workaround.

billhsln

You can do:

DEF a[3] as INT

RESTORE mydata

FOR x = 0 to 2
   GETDATA mydata,a[x]
PRINT a
NEXT x

DO:UNTIL INKEY$ <> ""
END

DATABEGIN mydata
DATA 100,200,300
DATAEND


Of course, this will also do:

DEF a[3]:int
a = 100,200,300
When all else fails, get a bigger hammer.

yujinwunz

Quote from: Parker on January 23, 2009, 01:12:39 PM
No, I don't believe you can. I can't exactly figure out what that statement would do either (would mydata[3] point to the block of data or would it create just a regular array?) - if you explain what you're trying to do we can help you with a workaround.

it would point to the block of data, so like


DATABEGIN mydata[0]
'some level data
DATAEND

DATABEGIN mydata[1]
'some level data
DATAEND

DATABEGIN mydata[2]
'some level data
DATAEND

DATABEGIN mydata[3]
'some level data
DATAEND




then get it like an array:

thecurrentlevel = 3
FOR x = 0 to 10

   GETDATA mydata[thecurrentlevel],a[x]

NEXT x


billhsln

I don't think EBasic will handle it directly, but you could do:

DATABEGIN mydata0
'some level data
DATAEND

DATABEGIN mydata1
'some level data
DATAEND

DATABEGIN mydata2
'some level data
DATAEND

DATABEGIN mydata3
'some level data
DATAEND

thecurrentlevel = 3
FOR x = 0 to 10

  SELECT thecurrentlevel
     CASE 0   
            GETDATA mydata0,a[x]
     CASE 1
            GETDATA mydata1,a[x]
     CASE 2
            GETDATA mydata2,a[x]
     CASE 3
            GETDATA mydata3,a[x]
   ENDSELECT

NEXT x

When all else fails, get a bigger hammer.

Parker

It looks like someone already found a solution while I was creating mine. This is an alternative that uses pointers so that you can use it like an array. It's modified from the user's guide sample.
DEF a,b as INT

def array[3] as pointer
array[0] = data1
array[1] = data2
array[2] = data3

print "which data to get (1-3)? ",
input a
a--
if a > 2 or a < 0 then a = 0

RESTORE *<datablock>(array[a])

FOR x = 1 to 3
   GETDATA *<datablock>(array[a]),b
PRINT b
NEXT x

DO:UNTIL INKEY$ <> ""
END

DATABEGIN data1
DATA 1,2,3
DATAEND

databegin data2
data 4,5,6
dataend

databegin data3
data 7,8,9
dataend

yujinwunz

thanks for the responses, but ill use pointers. :) why didn't i think of that before? ???