!*************************** AMUS Program Label ******************************
! Filename: GETFPN.BAS                                      Date: 12/13/92
! Category: ESP          Hash Code: 446-151-162-266      Version: 1.0(100)
! Initials: GR/AM        Name: JAMES A. JARBOE IV
! Company: EDUCATIONAL VIDEO NETWORK, INC          Telephone #: 4092955767
! Related Files: GETFPN.M68, GETFPN.SCR, SKPFLD.SBR
! Min. Op. Sys.: 1.3D                          Expertise Level: BEG
! Special: Must have TOOLBX.SYS installed and GETFPN.SBR
! Description: Basic program to test out and demonstrate the usage of
! GETFPN.SBR.
!
!*****************************************************************************
!*! Updated on 13-Dec-92 at 7:27 PM by James A. Jarboe I V; edit time: 0:14:37
!*! Created on 13-Dec-92 at 6:16 PM by James A. Jarboe I V; edit time: 0:14:04
!***************************************************************************
! GETFPN.BAS - Tests GETFPN.SBR
!***************************************************************************
!
! This Program is a completement to GETFID.BAS
!
! GETFPN.SBR returns the PERMANENT ID NUMBER of an ESP Screen field using
!            the ESP Screen's current FIELD NUMBER.
!
! GETFID.SBR returns the FIELD NUMBER of an ESP Screen field using the
!            ESP Screen's field PERMANENT ID NUMBER. (SEE GETFID.BAS)
!
! This program tests the GETFPN.SBR which is to be used with ESP and TOOLBX.
! One gripe of ESP users is the unavailability to allow the user to
! modify the sequence of an ESP screen entry and always get, set or
! evaluate the proper information from the ESP screen to the basic
! program variables without changing the BASIC program or using some
! elaborate table that must always be modified correctly.
!
PROGRAM GETFPN, 1.0(100)
!
! THE GETFPN.SBR helps to overcome this problem by allowing the program
! to access an ESP screen Fields PERMANENT ID NUMBER and base evaluations
! upon the PERMANENT ID NUMBER as offset by the screen's current FIELD
! NUMBER.
!
! This program uses:
!   SYSSTD.BSI   (Provided with ESP)
!   TOOLBX.SBR   (Provided with ESP)
!   TOOLBX.BSI   (Provided with ESP)
!   ERRSBR.BSI   (Provided with ESP)
!   GETFPN.SCR   (Provided on AMUS NETWORK by James A. Jarboe IV)
!   GETFPN.SBR   (Provided on AMUS NETWORK by James A. Jarboe IV)
!                 Source also provided  (GETFPN.M68)
!   SKPFLD.SBR   (Provided on AMUS NETWORK by James A. Jarbow IV)
!
! Any comments, suggestions, gripes should be directed to:
! GR/AM on the AMUS Network.
!
++include TOOLBX.BSI    ! include standard TOOLBX symbolics.
++include SYSSTD.BSI    ! include standard ESP symbolics.
!
map1    SCREEN$,  S, 34 ! Screen to try out
map1    FLDCNT,   F, 6  ! Number of fields in screen.
map1    FLDID,    F, 6  ! Permanent Field ID.
map1    PFLD(50), F, 6  ! Permanent fields.
                       ! Make big incase more screen fields are added.
map1    CFLD(50), F, 6  ! Current field (Field Number)
map1    CURNT'PERM'FIELD, F, 6
map1    PER'OFF,  F, 6  ! Permanent offset for SETVAL for POSTEDITing

! Set permanent field offset for SETVAL call when setting field values.
! We use 6 because we are using a generic call to SET values and the
! first SET value permanent field value is 7 because I used permanent
! field 6 for something else. So the logic will be (PER'OFF+X)
!
PER'OFF = 6

! Set screen to use
!
SCREEN$ = "GETFPN.SCR"

!***************************************************************************
! GETFPN
!***************************************************************************
!
GETFPN:
! Properly initialize terminal.
!
       xcall INITRM, "GETFPN.SBR Test Program","By James A. Jarboe IV"

! Properly Fetch screen.
!
       xcall FETCH, SCREEN$, SCREEN, X
       if X call FETCH'ERROR : goto FINISHED

! Get Number of fields in this screen.
!
       xcall TOOLBX, TBX'FLDCNT, SCREEN, FLDCNT

! GETFPN.SBR does the following:
! Returns the current PERMANENT FIELD NUMBER of the current FIELD NUMBER
! of an ESP SCREEN FIELD.
!
! GETFLD, SCREEN, CURRENT'FIELD, PERM'FIELD

! Get and store the PERMANENT FIELD NUMBER of all current FIELD NUMBERs.
! Also, pre-SKIP all fields.
!
       for X = 1 to FLDCNT

! Here is where we get the PERMANENT FIELD NUMBER of the current FIELD NUMBER
! An ESP Screen's current FIELD NUMBER is the one that can be changed in SEDIT
! to modify the entry sequence. The PERMANENT FIELD NUMBER is the one that
! cannot be changed. Set your user READ SECURITY LEVEL to 254 to see an
! an ESP screen's field PERMANENT FIELD NUMBER. This is the one displayed to
! the right of the Field Number: in CHANGE mode in SEDIT.
!
! Get Current field's Permanent ID number.
!
               xcall GETFPN, SCREEN, X, CFLD(X)

! Here, through math, we store the current FIELD NUMBER, of the
! current PERMANENT FIELD NUMBER so that we can use it to SETVAL or
! GETVAL or evaluate expressions based on that situation.
!
               if CFLD(X) <> 0 PFLD(CFLD(X)) = X
               xcall SKPFLD, SCREEN, TRUE, X
       next X

! Allow entry into only PERMANENT FIELDS 1-5 no matter what the user
!  has changed them to.
!
       for X = 1 to 5
               xcall SKPFLD, SCREEN, FALSE, PFLD(X)
       next X

       CHAR = ESP'BEGLIN   ! Set begginning of line.

! Set PERMANENT FIELD 1 as the field we always enter first no matter
!  what the user changed the value to by using SEDIT.
!
       FIELD = PFLD(1)     ! Set first field as Permanent field 1


       xcall OPNSCR, SCREEN ! Always properly open screen.

! Normal GTSCR processing.
!
GTSCR:
       xcall GTSCR, SCREEN, CHAR, FIELD

       if (CHAR and 255) = ESP'MENU goto FINISHED

       if (CHAR and ESP'POSTEDIT) call POST'EDIT

       if (CHAR and ESP'PREEDIT) call PRE'EDIT

       if (CHAR and 255) = ESP'EXECUTE call EXECUTE

       goto GTSCR


! Post Edit situation.
!
POST'EDIT:

! First we get the Current permanent field number based upon the current
! FIELD we are POST'EDITing from. This will allow us to get the proper
! variable from the proper string based upon the field's permanent ID
! number so it will always be correct.
!
       CURNT'PERM'FIELD = CFLD(FIELD)

! POST EDIT process according to Proper PERMANENT field value.
!
       ON CURNT'PERM'FIELD call PFLD'1, PFLD'2, PFLD'3 , PFLD'4, PFLD'5
       return

! Do your own Post editing based upon the permanent field value.
!
PFLD'1:
PFLD'2:
PFLD'3:
PFLD'4:
PFLD'5:

! Get the proper value from the proper field based upon the current
! field we are editing offset by the proper PERMANENT field.
!
       xcall GETVAL, SCREEN, PFLD(CURNT'PERM'FIELD), X$

! Set the proper value from the proper field based upon the current
! field we are editing offset by the proper PERMANENT field.

       xcall SETVAL, SCREEN, PFLD(CURNT'PERM'FIELD+PER'OFF), X$
       return


! Could be similar to above.
!
PRE'EDIT:
       return

EXECUTE:

! Get values from permanent fields 1-5 and set them in permanent fields
! 7-11  (Note Fields 7-11 are used instead of 6-10 because when I created
! the GETFPN.SCR I used permanent field 6 for something esle, thus
! permanent field 6 does not follow permanent field 5 for the situation
! I have created.  The next permanent field after permanent field 5 that
! this program will be using is permanent field 7. The user can change the
! FIELD NUMBER to what they want and the correct values will always be
! set in the proper fields.
! X will equal the permanent field values.

       for X = 1 to 5
       xcall GETVAL, SCREEN, PFLD(X), X$     ! Get permanent field value.
       xcall SETVAL, SCREEN, PFLD(X+PER'OFF), X$   ! Set permanent field.
       next X

       return

FINISHED:
       xcall CLSSCR, SCREEN    ! Always properly close screen.
       xcall INITRM            ! De-initialize terminal.
       END


FETCH'ERROR:
       xcall ALERT, "FETCH ERROR - "+STR(X)
       return


++include ERRSBR.BSI    ! include ERROR ROUTINE.