

[menu]  'display menu options

    cls
    print "**ANNUAIRE**"
    print
    print " 1) Ajouter un numéro"
    print
    print " 2) Rechercher un nom "
    print
    print " 3) Information sur ce logiciel"
    print
    print " 4) Quitter"
    print
    print " 5) Tuto"
    print
    print "Choisissez une option de 1 a 5."
    print
    input ">"; option

    if option < 1 or option > 5 then gosub [badOption]
    if option = 1 then gosub [enterAPhoneCall]
    if option = 2 then gosub [recherche]
    if option = 3 then [info]
    if option = 4 then [quitter]
    if option = 5 then [tuto]

    goto [menu]

[badOption]
    print
    beep
    print "L'option "; option; " n'existe pas."
    print "Appuyez sur une touche."
    dummyVar$ = input$(1)

    return
[enterAPhoneCall]  'accept a phone log entry from the user

    cls
    print "**Ajouter un appel**"
    print

    input "Nom : "; personCalled$
    input "Numero de telephone : "; callersPhone$


[saveEditCancelLoop]  'give the user the option to save, edit or abort

    cls
    gosub [displayEntryInfo]
    print "Sauvegarder,Modifier,Effacer (S/M/E)?";
    answer$ = input$(1)

    if answer$ = "S" or answer$ = "s" then gosub [saveEntry] : goto [menu]
    if answer$ = "M" or answer$ = "m" then gosub [editEntry]
    if answer$ = "E" or answer$ = "e" then [menu]

    goto [saveEditCancelLoop]


[displayEntryInfo]  'display call information

    print "        Nom  : "; personCalled$
    print "Numero de telephone : "; callersPhone$

    return


[editEntry]  'edit call information

    cls
    print "**Modifications**"
    print


    print "   Nom : "; personCalled$
    input "  Appuyez sur Entree,ou retapez > "; newEntry$
    if newEntry$ <> "" then personCalled$ = newEntry$

    print "Numero : "; callersPhone$
    input " Appuyez sur Entree,ou retapez > "; newEntry$
    if newEntry$ <> "" then callersPhone$ = newEntry$

    return


[saveEntry]  'write the entry info to PHONELOG.TXT

    open "PHONELOG.TXT" for append as #out
    print #out, personCalled$
    print #out, callersPhone$

    close #out

    return
[quitter]

end

[info]
cls
print
print "Ce logiciel a été programmé par la société ALMD"
print
print "Ce logiciel est gratuit"
print
print "Le site web de la société : http://www.almd-jb.sitew.com/#Presentation.A"
print
input "Appuyer sur une touche pour revenir au menu";bidon
goto[menu]


[recherche]  'look for a phone log entry by person called

    cls
    print "**Rechercher un nom**"
    print
    print "Entrer le début du nom"
    input ">"; searchCalled$
    if searchCalled$ = "" then [menu]  'nothing entered, abort search

    searchCalled$ = upper$(searchCalled$) 'convert to uppercase for search

    open "PHONELOG.TXT" for input as #in

    foundFlag = 0
    quitFlag = 0
    if eof(#in) = -1 then [endOfCalledSearch]


[searchByCalledLoop]
    gosub [readEntry]  'get next entry from PHONELOG.TXT
    if instr(upper$(personCalled$), searchCalled$) > 0 then gosub [matched]
    if eof(#in) = 0 and quitFlag = 0 then [searchByCalledLoop]


[endOfCalledSearch]
    close #in
    if foundFlag = 0 then print "Ce nom n'existe pas"
    print "Appuyer sur entrer pour revenir au menu"
    dummyVar$ = input$(1)
    goto [menu]


[readEntry]  'read the next entry from PHONELOG.TXT

    line input #in, callersName$
    line input #in, callersPhone$

    return


[matched]  'stop and show a match & ask what to do next

    foundFlag = 1
    print "---------Trouvé---------"
    gosub [displayEntryInfo]
    print
    print "Appuyer sur N pour revenir en arrière ou Q revenir au menu (N/Q)?"
    answer$ = input$(1)
    'only check for quit response
    if answer$ = "Q" or answer$ = "q" then quitFlag = 1

    return

[tuto]


    open "tuto.TXT" for append as #out2
    close #out2
open "tuto.txt" for input as #out2

while eof(#out2) <> -1
    input #out2,ligne$
    print ligne$
wend
wait
close #out2


    return
