home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI09.ARJ / ictari.09 / GFA / HINTS / JC_HINTS.TXT
Text File  |  1994-03-27  |  5KB  |  129 lines

  1.  
  2.                              GFA PROGRAMMING TIPS
  3.                              ====================
  4.  
  5.                                 By John Charles
  6.  
  7.     Three tips  for  GFA  Basic3  programmers  using  coding  from  JCLABEL
  8.     originally  written  for  GFA   Basic   Users   Group  Diskzine  (GBUG,
  9.     California, USA) in 1993
  10.  
  11.     WHERE IS MY PROGRAM ????????
  12.  
  13.     When the user of your program wants to  load or save a file it is often
  14.     useful to present  the  user  with  the  file-selector  pointing at the
  15.     folder which contains the program. The following two lines of code when
  16.     placed  near  the  beginning   of   the   program   code  (or  in  your
  17.     initialisation procedure) will let you  know  exactly where the program
  18.     was when it was first run....
  19.  
  20.     drive%=GEMDOS(25)
  21.  
  22.     disk$=CHR$(drive%+65)+":"+DIR$(0)+"\"
  23.  
  24.     The first line returns a number in drive%
  25.  
  26.     where 0 = drive A, 1 = drive B, 2 = drive C, etc.....
  27.  
  28.     The second line converts  this  to  the correct letter CHR$(drive%+65),
  29.     adds the colon, makes a call DIR$(0) which returns the rest of the path
  30.     and finally adds a final backslash.
  31.  
  32.     So, if the program JCLABEL is on drive  E and buried in a folder called
  33.     JC_PROGS and then inside  another  folder  called  JCLABEL the variable
  34.     disk$ will contain E:\JC_PROGS\JCLABEL\
  35.  
  36.     If it was in the root directory of  a floppy in drive A then disk$ will
  37.     just contain A:\
  38.  
  39.     This information may be used when you call the file-selector to present
  40.     this path when looking for the label lists...
  41.  
  42.     I then use...
  43.  
  44.     FILESELECT #"LOAD AN ADDRESS LIST",disk$+"*.JCL",default$,fname$
  45.  
  46.     to call the file-selector which does several things at once.
  47.  
  48.     First using the #  variation  lets  you  send  a  message  to the file-
  49.     selector which will be printed at the  top  if you have TOS1.4 or later
  50.     or are using a third  party  file-selector  like UISIII or Little Green
  51.     Selector. In this case the message LOAD AN ADDRESS LIST is sent.
  52.  
  53.     Next the route to the  folder  containing  the  program is sent (disk$)
  54.     which has, in this case, *.JCL added so the fileselector shows only the
  55.     files ending with the extender JCL
  56.  
  57.     Thirdly, default$ should contain the name  of any default file-name you
  58.     may want to present to the user otherwise just use a null string ("")
  59.  
  60.     In my case I use
  61.  
  62.     default$=disk$+"MYADLIST.JCL"
  63.  
  64.     Lastly the variable fname$ lets you  know  what the user has chosen. If
  65.     they selected a file or typed in  a  file-name and clicked OK or double
  66.     clicked on a file-name, fname$  will  contain  the full path along with
  67.     the name of the file. If they clicked CANCEL then fname$ will be a null
  68.     string "".
  69.  
  70.     KEEPING AN AUTOMATIC BACKUP FILE
  71.  
  72.     Some programs automatically keep a backup  of  the last copy of a file,
  73.     just in case it  is  needed  again.  JCLABEL  now  does  this as it was
  74.     requested by a user with  several  long  address  lists who lost one by
  75.     typing the wrong name late one tiring night.
  76.  
  77.     How can you do that then? Easily  as  long  as one or two simple checks
  78.     are made along the way.
  79.  
  80.     Here is part of the code from JCLABEL...
  81.  
  82.     bakup$=LEFT$(fname$,LEN(fname$)-3)+"BAK"
  83.  
  84.     IF EXIST(bakup$)
  85.  
  86.       KILL bakup$
  87.  
  88.     ENDIF
  89.  
  90.     IF EXIST(fname$)
  91.  
  92.       RENAME fname$ AS bakup$
  93.  
  94.     ENDIF
  95.  
  96.     That's it!! Next the code carries on to save the new file as normal.
  97.  
  98.     To explain the above...
  99.  
  100.     First take the  full  path  and  filename  which  the file-selector has
  101.     returned to you in fname$ (or whatever  you  want to call it) and strip
  102.     off the last three characters which is what LEFT$(fname$,LEN(fname$)-3)
  103.     does and add in the new BAK extension.
  104.  
  105.     Next check to see if an old backup file already exists and delete it.
  106.  
  107.     Now see if the original file-name already exists and rename it with the
  108.     extender BAK
  109.  
  110.     It may seem a strange order  to  do  the things but this process covers
  111.     all eventualities and doesn't  fall  flat  on  its  face  if it's a new
  112.     filename (nothing to backup and no backup  to  delete) or if there is a
  113.     file which hasn't been backed up yet.
  114.  
  115.     I find that the error  checking  sections  of programming take the most
  116.     thinking out (trying to  imagine  all  possible  actions and mistakes a
  117.     user might make) and the longest testing time but in the end it's these
  118.     little bits which the user never  notices  but which can make a program
  119.     user friendly.
  120.  
  121.     I hope that these few hints will  have been useful to someone out there
  122.     starting with GFA - don't  give  up  too  easily,  we all have to start
  123.     somewhere and there's always someone willing to answer queries.
  124.  
  125.     This text file may  be  distributed  freely  by  anyone  for non profit
  126.     purposes as long as it remains unaltered.
  127.  
  128.     BeST wishes  >> JayCee <<  March, 1994
  129.