GFA PROGRAMMING TIPS ==================== By John Charles Three tips for GFA Basic3 programmers using coding from JCLABEL originally written for GFA Basic Users Group Diskzine (GBUG, California, USA) in 1993 WHERE IS MY PROGRAM ???????? When the user of your program wants to load or save a file it is often useful to present the user with the file-selector pointing at the folder which contains the program. The following two lines of code when placed near the beginning of the program code (or in your initialisation procedure) will let you know exactly where the program was when it was first run.... drive%=GEMDOS(25) disk$=CHR$(drive%+65)+":"+DIR$(0)+"\" The first line returns a number in drive% where 0 = drive A, 1 = drive B, 2 = drive C, etc..... The second line converts this to the correct letter CHR$(drive%+65), adds the colon, makes a call DIR$(0) which returns the rest of the path and finally adds a final backslash. So, if the program JCLABEL is on drive E and buried in a folder called JC_PROGS and then inside another folder called JCLABEL the variable disk$ will contain E:\JC_PROGS\JCLABEL\ If it was in the root directory of a floppy in drive A then disk$ will just contain A:\ This information may be used when you call the file-selector to present this path when looking for the label lists... I then use... FILESELECT #"LOAD AN ADDRESS LIST",disk$+"*.JCL",default$,fname$ to call the file-selector which does several things at once. First using the # variation lets you send a message to the file- selector which will be printed at the top if you have TOS1.4 or later or are using a third party file-selector like UISIII or Little Green Selector. In this case the message LOAD AN ADDRESS LIST is sent. Next the route to the folder containing the program is sent (disk$) which has, in this case, *.JCL added so the fileselector shows only the files ending with the extender JCL Thirdly, default$ should contain the name of any default file-name you may want to present to the user otherwise just use a null string ("") In my case I use default$=disk$+"MYADLIST.JCL" Lastly the variable fname$ lets you know what the user has chosen. If they selected a file or typed in a file-name and clicked OK or double clicked on a file-name, fname$ will contain the full path along with the name of the file. If they clicked CANCEL then fname$ will be a null string "". KEEPING AN AUTOMATIC BACKUP FILE Some programs automatically keep a backup of the last copy of a file, just in case it is needed again. JCLABEL now does this as it was requested by a user with several long address lists who lost one by typing the wrong name late one tiring night. How can you do that then? Easily as long as one or two simple checks are made along the way. Here is part of the code from JCLABEL... bakup$=LEFT$(fname$,LEN(fname$)-3)+"BAK" IF EXIST(bakup$) KILL bakup$ ENDIF IF EXIST(fname$) RENAME fname$ AS bakup$ ENDIF That's it!! Next the code carries on to save the new file as normal. To explain the above... First take the full path and filename which the file-selector has returned to you in fname$ (or whatever you want to call it) and strip off the last three characters which is what LEFT$(fname$,LEN(fname$)-3) does and add in the new BAK extension. Next check to see if an old backup file already exists and delete it. Now see if the original file-name already exists and rename it with the extender BAK It may seem a strange order to do the things but this process covers all eventualities and doesn't fall flat on its face if it's a new filename (nothing to backup and no backup to delete) or if there is a file which hasn't been backed up yet. I find that the error checking sections of programming take the most thinking out (trying to imagine all possible actions and mistakes a user might make) and the longest testing time but in the end it's these little bits which the user never notices but which can make a program user friendly. I hope that these few hints will have been useful to someone out there starting with GFA - don't give up too easily, we all have to start somewhere and there's always someone willing to answer queries. This text file may be distributed freely by anyone for non profit purposes as long as it remains unaltered. BeST wishes >> JayCee << March, 1994