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?
Reading from a file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Hola,
maybe this will help:
Sorry, no idea of databases...
Best
Klaus
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...
...
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
- Contact:
If you just want the last 30, and less if there aren't 30 then maybe this can help you:
To find out wether there's less then 30 items, you can use this:
Code: Select all
put item -30 to -1 of theList into theLastThirty
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
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Getting numbers...
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-
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!
-
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
- Contact:
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
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode