Page 1 of 1

Reading from a file

Posted: Wed Feb 13, 2008 2:17 pm
by bjb007
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?

Posted: Wed Feb 13, 2008 2:33 pm
by Klaus
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

Posted: Wed Feb 13, 2008 2:43 pm
by BvG
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

Getting numbers...

Posted: Wed Feb 13, 2008 4:28 pm
by bjb007
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!

Posted: Thu Feb 14, 2008 12:02 am
by BvG
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.