Blitz (53/64)

From:David McMinn
Date:27 Apr 2001 at 17:51:12
Subject:Re: BlitzII Programming Restart

Hi Terje

> I got a few question if I'm allowed

Of course, that is what this list is for :)

> ? tell me wich files and dirs that exists in a destination
> This is a big problem. I can't seem to find
> any commands in the manual able to do this.

There is no single command to do this, but there is an example of this provided
with Blitz (either on the "Examples" disk or in the "Examples" drawer on the
CD. You should look for the source file called mydir.bb or mydir2.bb.

There is also an example on Aminet, and is probably better than those two
examples:

http://ftp.uni-paderborn.de/pub/aminet/dev/basic/ReadDirs.lha

> ? open a file, to read and write from it at random locations.
> I found the PUT and GET commands in the Manual, even in
> an example. But still I could NOT figure out the logic
> how these commands work.

Initially you open the file:

#FILE_NUMBER = 0
If OpenFile(#FILE_NUMBER, "filename")

Then you must have a fixed (I think) record format. This is how the data will
be stored in the file.

For example, if we wanted to store a string and number for each record (it
might help to think of it like a database) we would need to create a couple of
variables for storing this information and then specify the record format:

DEFTYPE.w some_number
DEFTYPE.s some_string : MaxLen some_string=192
Fields #FILE_NUMBER,some_string,some_number

We need to give all strings used in records a maximum length using the MaxLen
command. The strings you use with this file can not be longer than the length
you specify in the MaxLen command. The variables you use in the Fields command
will be the variables you use to "communicate" with the file. So now that we
have the file open and the record format set up, we can read and write from the
file.

First of all the structure of the file in this example will be like this:

Record number Variable Variable .....
in file type type

1 string word
2 string word
3 string word
... ... ...
n string word

So as you can see, each record in the file has the same types as you specify
with the Fields command.

Now, to write something to the file, we need to put values in the variables you
specify in the Fields command (remember, these are the ones you use to
communicate with the file) and issue the Put command. So, to put something as
the first entry in the file, we would use:

some_string = "This is the first item in the file!"
some_number = 69
Put #FILE_NUMBER,1

This information will then be stored in the file, at record number 1. You can
write any number of other records to the file, at any record position, but you
must set the values to be stored in the variables some_string and some_number.

Now, if we wanted to read a record from the file, you issue the Get command. In
this example, if you have not written anything else to record 1, it should
still have the above data in it:

some_string = "" ; These two are just to prove that the values get read from
some_number = 0 ; the file. You would not normally include these.
Get #FILE_NUMBER,1 ; Read the values from the file
NPrint some_string ; These should show the same data as we originally put
NPrint some_number ; to the file earlier

So now you can do as many Put's or Get's on the file as you want. When finished
with it, you would simply do:

CloseFile #FILE_NUMBER
EndIf

Basically you tell the commands what variable to communicate through and then
Put will copy from the variable->file and Get will read from the file into the
variables you specified. In the case of these files, I do not think you need to
use FileOutput to redirect the data to the file.

Hope that helps.



|) /\ \/ ][ |) |\/| c |\/| ][ |\| |\| | dave@blitz-2000.co.uk
http://members.nbci.com/david_mcminn | ICQ=16827694
If you paint your butt blue and glue your bunghole shut you just 'themed'
your butt, but lost the functionality

---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list/-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list/-help@netsoc.ucd.ie