IonicWind Software

IWBasic => General Questions => Topic started by: yujinwunz on January 23, 2009, 03:04:20 AM

Title: data array
Post by: yujinwunz on January 23, 2009, 03:04:20 AM
very quickly, can i define data blocks with arrays? eg.

DATABEGIN mydata[3]
...
DATAEND


thanks
yujin
Title: Re: data array
Post by: 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.
Title: Re: data array
Post by: billhsln on January 23, 2009, 03:15:00 PM
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
Title: Re: data array
Post by: yujinwunz on January 23, 2009, 03:26:15 PM
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

Title: Re: data array
Post by: billhsln on January 23, 2009, 05:21:38 PM
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

Title: Re: data array
Post by: Parker on January 23, 2009, 05:32:32 PM
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
Title: Re: data array
Post by: yujinwunz on January 23, 2009, 06:55:54 PM
thanks for the responses, but ill use pointers. :) why didn't i think of that before? ???