Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / can you extend an array

Author
Message
pollywog
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location:
Posted: 10th Jul 2010 04:03
I am attempting to read a text file into an array

so I have something like dim() v_mtype as mytype

then I want to do something like
while file end(1) = 0
i = i + 1
mytype.extend
read string 1, mytype(i).mystring
endwhile
close file 1

is that possible?
Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 10th Jul 2010 04:45
I think the array insert and array count commands are what you are after here. e.g.




I have never had any luck reading from a file directly into an array, hence the use of the temporary T$ variable to transfer the read data to the array.

This is not the Sig you are looking for....
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th Jul 2010 00:24
Arrays maintain a 'current item' value that isn't accessible (unless you use my plug-ins), but can be used by not specifying an index for your array.

When you insert into an array using any of the ARRAY INSERT commands, the STACK or the QUEUE commands, the inserted item becomes the current item.



There are examples of stack, queue and list commands in use in the codebase under my name:
List: http://www.thegamecreators.com/?m=codebase_view_code&i=6c72fb1f0eb1323aad0aacb21d767115
Stack: http://www.thegamecreators.com/?m=codebase_view&i=66bdf7a5604abcf6d22bfa8b3fae388f
Queue: http://www.thegamecreators.com/?m=codebase_view_code&i=1b1bafde877fabb221079f01fd849690

The only thing that isn't totally accurate in those pieces of code is that it is possible now to create an empty array:


One further thing is that the end of file is not set when you've read the last item in the file. It is set when you try to read from the file and there's nothing left to read - ie, with 5 lines in a file, you won't get FILE END(1) set to 1 until the 6th read.

pollywog
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location:
Posted: 15th Jul 2010 06:39
thanks guys
actually I was lazy and cheated
I opened the file and incremented a counter while I did the reade
and closed the file

then I made an array with counter number of items.

then I opened up the file again and read the items into the array.
cloudy
14
Years of Service
User Offline
Joined: 30th Jun 2010
Location:
Posted: 15th Jul 2010 10:51
there are difficult to do it.

Your signature has been erased by a mod

Login to post a reply

Server time is: 2024-11-24 14:02:28
Your offset time is: 2024-11-24 14:02:28