Navigation:  Macro > Exemples >

EXEMPLE MACRO21

AiM Services
Previous pageReturn to chapter overviewNext page

Adresses

Gestion simple d'adresses avec utilisation de la fenêtre de type forme et utilisation d'un fichier à accès direct.
 

Exemple

 MACRO "adresses.mac"
 !
   COM @File,File$,Rec_len,Nb_adr,Num_adr
 ! Nom du fichier adresse
   TEXT INIT "/tell/macro/exemple/ADRESSE.txt";File$
 ! Taille d'un enregistrement
   Rec_len=172
   Num_adr=0
 ! Ouverture du fichier adresse
   CALL Open_file
 ! Initialisation de la forme
   FORMS SET SIZE 14,56
   FORMS INIT 50
   FORMS COLOR 6,1
   FORMS DEF 1,1,0,4,"ADDRESS CONTROL"
   FORMS COLOR 1
   FORMS DEF 2,1,0,5
   FORMS DEF 3,1,0,2,"Number of adresses"
   FORMS DEF 4,1,0,2,"Address N°"
   FORMS DEF 5,1,0,2,"NAME"
   FORMS DEF 6,1,0,2,"FIRST NAME"
   FORMS DEF 7,1,0,2,"ADDRESS"
   FORMS DEF 8,1,0,2,"CITY"
   FORMS DEF 9,1,0,2,"COUNTRY"
   FORMS DEF 10,1,0,2,"TELEPHONE"
   FORMS DEF 11,1,0,5
   FORMS DEF 12,1,0,2,"[ESC] To stop"
   FORMS DEF 13,1,0,5
   FORMS COLOR 2,1
   FORMS DEF 3,21,4,2,"0"
   FORMS DEF 4,12,4,2,"0"
   FORMS DEF 5,12,30,3,"",Entree_nom
   FORMS DEF 6,12,30,3,""
   FORMS DEF 7,12,40,3,""
   FORMS DEF 8,12,30,3,""
   FORMS DEF 9,12,20,3,""
   FORMS DEF 10,12,16,3,""
   FORMS COLOR 1,0
   FORMS LABEL 0,"WRITE",Ecrire
   FORMS LABEL 1,"LIST",Liste
   FORMS LABEL 7,"EXIT",Fin_masque
   FORMS MODIFY 13,Nb_adr
 ! Gestion des adresses
   FORMS INPUT
   FORMS CLOSE
   END
 ! Recherche et affichage de l'adresse si le nom est déjà dans le fichier
   SUB Entree_nom
     FORMS GET ZONE Num
     FORMS READ Num;Nom$
     CALL Search(Nom$,Num)
     FORMS MODIFY 14,Num_adr
   SUBEND
 ! Sortie du masque
   SUB Fin_masque
     FORMS RETURN KEY 8
   SUBEND
 ! Ouverture du fichier adresse
   SUB Open_file
     OPEN ASCII @File TO File$;Err
     IF Err THEN
       CREATE File$;Err
       IF Err THEN STOP
       OPEN ASCII @File TO File$;Err
       SEEK @File,0
       OUTPUT @File,0
     END IF
     SEEK @File,0
     ENTER @File;Nb_adr$
     TEXT VAL Nb_adr$,1;Nb_adr
   SUBEND
 ! Ecriture de l'adresse courante
   SUB Ecrire
     IF Num_adr=0 THEN
       SEEK @File,0
       ENTER @File;Nb_adr$
       TEXT VAL Nb_adr$,1;Nb_adr
       Nb_adr=Nb_adr+1
       SEEK @File,0
       OUTPUT @File,Nb_adr
       Num_adr=Nb_adr
     END IF
     SEEK @File,Num_adr*Rec_len
     FOR I=15 TO 20
       FORMS READ I;Zone$
       OUTPUT @File,Zone$
     NEXT I
     FORMS MODIFY 13,Nb_adr
     FORMS MODIFY 14,Num_adr
   SUBEND
 ! Recherche d'une adresse
   SUB Search(Nom$,Num)
     FOR Num_adr=1 TO Nb_adr
       SEEK @File,Num_adr*Rec_len
       ENTER @File;Zone$
       TEXT CMP Zone$,Nom$;Test
       IF Test=0 THEN
         FOR I=16 TO 20
           ENTER @File;Zone$
           FORMS MODIFY I,Zone$
         NEXT I
         SUBEXIT
       END IF
     NEXT Num_adr
     Num_adr=0
   SUBEND
 ! Liste des adresses
   SUB Liste
     FORMS VIEW OFF
     ALPHA CLEAR
     FOR I=1 TO Nb_adr
       SEEK @File,I*Rec_len
       ENTER @File;Nom$,Prenom$,Lieu$,Adr$,Pays$,Tel$
       PRINT USING "K,""|""";Nom$,Prenom$,Lieu$,Adr$,Pays$,Tel$
     NEXT I
     ALPHA VIEW
     FORMS VIEW ON
   SUBEND
   END MACRO