+----------------------------------------------------------------------+
|                       I * C * E * T * I * P * S                      |
|                                                                      |
|                       Nr 2,  February 25th 1995                      |
|                                                                      |
|                         Presented to you by                          |
|                      Arnor Baldvinsson, ICELAND                      |
+----------------------------------------------------------------------+

Want to have the system wait for a specified time?  Want to figure out
how many bytes a datafile is?

Here is some code to make this easy.  I had problems with the BYTES function
in CW to find out exactly how many bytes a datafile was.  The problem is
that if you have a file with one 2 byte record it still takes up 1024 bytes
on the hard disk (with dos 6.2 at least).  BYTES, however reports only 2
bytes.  
It wasn't reliable enough to use for diskspace calculation, so I 
created my own FileSize function which reports the actual number 
of bytes on the disk.  If you have a lot of almost empty data files BYTES
will tell you that you need only a few bytes of diskette space to make 
a copy but in fact you may need several kilobytes of disk space.  

First of all we need to create a file definition in the Global - Embedded
Source - Global Data.  You may do this with the dictionary, but I find it
easier to implement this way (BTW; you only need this for the FileSize 
function - if all you need is WAIT you can skip this):

!----------------------------------------------------------------BEGIN
DosFile                FILE,DRIVER('DOS'),NAME(FileName),PRE(DOS),THREAD
Record                   RECORD
Buffer                     BYTE,DIM(4096)
                         END
                       END
DosFile::Used LONG,THREAD
!----------------------------------------------------------------END

In the Global - Embeds - inside Global Map put the following code to
prototype the two functions:

!----------------------------------------------------------------BEGIN
MODULE('MYFUNC.CLW')
  WAIT(LONG)
  FILESIZE(FILE),Long
END
!----------------------------------------------------------------END

In the module MYFUNC.CLW put the following code:

!----------------------------------------------------------------BEGIN
Wait   PROCEDURE(tic)                   ! 1 tic = 1/100 second
  CODE
  T#=CLOCK()                            ! What time is it?
  LOOP WHILE CLOCK() < T#+TIC           ! Loop untill right time
  END                                   ! END LOOP WHILE...
RETURN                                  ! RETURN from WAIT

FileSize FUNCTION(FileLabel)            ! Passing Filelabel = FILE
                                        ! Local variables:
S    LONG                               ! Temporary FileSize var

  CODE
  CLOSE(FileLabel)                      ! Close the file first
  OPEN(FileLabel)                       ! And reopen it
  FileName = NAME(FileLabel)            ! Get the name of the file
  CLOSE(FileLabel)                      ! Close it again

  OPEN(DosFile)                         ! Open it as DOS file
  S = BYTES(DosFile)                    ! Get the size
  CLOSE(DosFile)                        ! Close it as DOS file
RETURN(S)                               ! Return the size of the file

!----------------------------------------------------------------END

Notice that the FileSize function will return with the passed file
CLOSEd.  In most cases this will be a function called from Procedure
setup or from procedures which open files "manually" from hand 
code not generated code, so you have control over which files are
open and which are not.


***** COMING UP NEXT on ICETIPS:  *****

Figure out what kind of display resolution you are using and get the 
current Windows version number and learn a little on Windows API 
in doing so.

