Reading from a file

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Reading from a file

Post by bjb007 » Wed Feb 13, 2008 2:17 pm

I have a file of numbers - 2,5,6,99
which might have ten numbers or 100.

I want to read the last, say, 30 - but of
course there mightn't be 30 numbers at
the start. They're comma-separated so
perhaps could count the commas.

Is there another way to count the number of "records"?

If I put them in a database is there a "reccount"
function? Haven't found any database help files.

Could read them all into an array then get the
last 30.

If I copy records into an array can I get the
number of records from the number of elements?

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Wed Feb 13, 2008 2:33 pm

Hola,

maybe this will help:

Code: Select all

...
put url("file:path/to/file_with_numbers.txt") into complete_file_content
put the num of items of complete_file_content into num_o_numbers
## Now you have the count of all numbers in the file

## Check now :
if num_o_numbers >= 30 then
    put item 1 to 30 of num_o_numbers into my30numbers
  else
...
end if
...
## do what ou want with my30numbers...
...
Sorry, no idea of databases...


Best

Klaus

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Wed Feb 13, 2008 2:43 pm

If you just want the last 30, and less if there aren't 30 then maybe this can help you:

Code: Select all

put item -30 to -1 of theList into theLastThirty
To find out wether there's less then 30 items, you can use this:

Code: Select all

if the number of items in theList > 30 then
  --do stuff here
end if
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Getting numbers...

Post by bjb007 » Wed Feb 13, 2008 4:28 pm

Thanks Klaus and BvG.

BvG-
Thought of doing that but expected there
might be an error thrown if there were <30
numbers.

Will try both ways and see what happens.

Later: Rev doesn't seem to mind that there
are fewer than 30 numbers!

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Thu Feb 14, 2008 12:02 am

The older, and therefore core parts of rev are made to be simple for humans to use. Of course that throws of most people that have used other programming languages, because they expect it to work like a computer. Unfortunately, almost all recent additions work like programmers know and expect.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”