Welcome to part 3 of resource programming in GFA Basic. This time 
I will cover getting information in and out of resources  (dialog 
boxes) using editable fields.
You  may  have noticed,  that over the  last  three  issues,  the 
programs  all start off the same way,  the management  of  dialog 
boxes always follows these simple steps:
1)   Reserve memory for the file - RESERVE.
2)   Free any existing resource memory - ~RSRC_FRE().
3)   Load in the resource file using RSRC_LOAD
     (you can do error detection (ie.  file failed to load)if you 
4)   Get the object numbers and tree address(es).
     (For multiple form resources - you need all the trees!)
5)   Put the dialog box onto the screen - using OBJC_DRAW.
6)   Pass control over to GEM via the FORM_DO command.
7)   Find out what objects were selected, and react as required.
8)   Remove the resource from memory ~RSRC_FRE(),  and relinquish 
     reserved memory.
Steps  5,6 and 7 can be repeated as required for your  particular 
This Month's Program
This  time,  the program and resource,  demonstrate how  to  pass 
information to,  and get information back from,  editable  fields 
within  a FORM.  You should have seen this type of input,  it  is 
presented by the ST when you want to create a folder,  or type in 
a  file name via the file selector.  You can put  default  values 
into these fields,  mask off unwanted entries,  and preformat the 
way the information is presented.
If you carefully read the introduction in the first part of  this 
series,  you may have noticed that I said that an editable  field 
can't be the last object within a form,  otherwise you will crash 
the ST.  So with this in mind,  always sort the objects when  you 
create them,  and if there is an editable object as the last one, 
create  a  dummy IBOX and hide it.  This does not  apply  to  our 
program, as the last object is an EXIT box.
The  idea of the program,  is that it stores phone  numbers;  you 
could  use this to auto phone a bulletin board,  or simply  as  a 
phone book.  
The resource file contains the usual EXIT boxes,  and  introduces 
some  new objects:  the left and right arrows (within a  box)  is 
called G_BOXCHAR,  the editable field is G_FTEXT.  The status  of 
the  boxed  characters  (the left and right  arrows)  is  set  as 
TOUCHEXIT.  This is slightly different to the normal DEFAULT/EXIT 
box.  An  object  with TOUCHEXIT status will send a  message  via 
FORM_DO  when  you click on it (as soon as you  press  the  mouse 
button),  whereas  an object which is selectable (like  the  EXIT 
box)  will only react when the mouse button has been pressed  and 
Some of the editable fields have been preformatted, ie. they have 
a mask.  If you type in a name in the file name area, it will put 
the '.' in for you.  So if you type 'ABC' and the press the  full 
stop,  the  cursor  will automatically go to the part  where  you 
enter the file's extender. The phone number also, has minus signs 
in it,  you cannot type over them, the AES does the formatting of 
the text you type in, for you.
The program flow looks like this:
______________________  error in loading ??
| Load resource file |------->-----------_______________________
         |                               |Try finding resource |
         |load ok?                          |             |     
         |----------------------<---<-------|ok           |failed
_________|______________                           _______|______
| Is there a data file?|                           | End program|
| then load it.        |                                         
| If data exists - put |
| it into resource     |-------<-----+
         |        ^                  ^
         |      < | >          ______|_________
_________|________|____        | no file name |
| edit resource boxes |               |        
    |             |         __________^________
    |             +-->------| clicked on SAVE |
    |                               |          
____|________________               |      
| Clicked on Cancel |               |
         |                          |
         |                          |
_________|_______                   |
|  EXIT PROGRAM |--------<----------+  
You can see from the flow chart, that the program is a continuous 
loop,  waiting for input,  if you select the left or right arrows 
(increase or decrease entry) you go back to the edit mode. If you 
click on SAVE,  but there is no file name specified,  then you go 
back to edit.
First set up room for the variables
DIM entry_no%(100),name$(100),location$(100)
DIM comment$(100),phone_number$(100)
next the normal load bit (see steps 1-3 above)
IF a&=0
  ALERT 1,"Can't find Resource file|Try and select it with|the fileselector",1,"OK",v|
  FILESELECT "i_o.rsc","",r$
  IF r$<>""
set up the variables
get the address of the structure
try to load the default file for the data
set number of entries to the start
calculate the coordinates for the form
now sit in a loop until finished
put your data onto the form, so you can edit it
draw the form on screen
hand over control to the AES,
clear the button that caused the exit from the form
get all entries from the form
  LET name$(entries%)=CHAR{{OB_SPEC(tree%,name|)}}
did you click on a right/left arrow?
  SELECT result|
  CASE decremnt|
    IF entries%>1
      DEC entries%
  CASE incrmt|
    IF entries%<100
      INC entries%
did you click on cancel?
  EXIT IF result|=cancel|
keep going until you click on SAVE and you have a file to save to
UNTIL result|=save| AND fname$<>""
save the file
IF result|=save|
all done
the resource variables here
PROCEDURE rsc_vars
  LET edit|=0                         ! DIALOG TREE
  LET decremnt|=1                     !   Boxed Char
  LET entryno|=2                      !   Formatted Text
  LET incrmt|=3                       !   Boxed Char
  LET name|=4                         !   Formatted Text
  LET locatn|=5                       !   Formatted Text
  LET comment|=6                      !   Formatted Text
  LET phoneno|=7                      !   Formatted Text
  LET file|=8                         !   String
  LET filename|=9                     !   Formatted Text
  LET cancel|=10                      !   Button
  LET save|=11                        !   Button
if a data file exists - load it
PROCEDURE load_dial_dir
    fname$="DIAL    DIR"
    OPEN "r",#1,"dial.dir",63
    FIELD #1,20 AS name$
    FIELD #1,16 AS location$
    FIELD #1,17 AS comment$
    FIELD #1,10 AS n$
      GET #1,n%
      LET name$(n%)=TRIM$(name$)
      INC n%
    CLOSE #1
save your file
PROCEDURE save_dial_dir
  OPEN "r",#1,fname$,63
  FIELD #1,20 AS name$
  FIELD #1,16 AS location$
  FIELD #1,17 AS comment$
  FIELD #1,10 AS n$
  FOR n%=1 TO entries%
    LSET name$=name$(n%)
    LSET location$=location$(n%)
    LSET comment$=comment$(n%)
    LSET n$=phone_number$(n%)
    PUT #1,n%
  NEXT n%
  CLOSE #1
I  have  used a random access file,  you could use any  type  you 
If you would like more information on resource programming in GFA 
Basic,  then I would reccomend two books.  For version 2 users  - 
Advanced  Programming  in  GFA Basic.  For V3  users  -  Software 
Development  in  GFA Basic.  Both available from GFA  Data  Media 
John Peters


(C) Marko, Suomen Atari-sivut / ArkiSTo 2003