' iBAddress.ibas
{CREATORID "LDIA"}
{VERSION "2.4"}
{RESOURCEFILE + "iBAddress.rsrc"}

CONST M$="Last name"
CONST N$="First name"
CONST O$="Birthday"
CONST Y$="iBAddress v2.4¶	September 17, 2007¶"
CONST Z$="	by Laurent Duveau¶	www.aldweb.com"

_InitDisplay:
   J=FILEEXISTS("iBAddrDB")
   IF J=1 THEN
      L=LOADPREF(#1)
      IF L>0 THEN
         K=LOADPREF(#2)
         I=LOADPREF(#3)
         S=LOADPREF(#4)
         T=LOADPREF(#5)
      ELSE S=1
      ENDIF
   ELSE S=1
   ENDIF
   LABEL #1,M$,5,18
   TEXTFIELD #2,"",0,55,18,100,15
   LABEL #3,N$,5,33
   TEXTFIELD #4,"",0,55,33,100,15
   LABEL #5,"Phone",5,48
   TEXTFIELD #6,"",0,55,48,100,15
   LABEL #7,"E-mail",5,63
   TEXTFIELD #8,"",0,55,63,100,15
   LABEL #9,O$,5,78
   TEXTSELECTOR #10,"",55,78,54,11
   LABEL #12,"Other",5,93
   TEXTFIELD #13,"",1,55,93,100,30
   LABEL #14,"Sort by:",5,122
   L$=M$+"¶"+N$+"¶"+O$
   J=12+S : J$=A$(J)
   POPUPCHOICE #15,J$,L$,3,40,120,60,15
   CHECKBOX #16,"Reverse",T,105,120,50,15
   LABEL #17,"1/1",42,142
   Q$=GETOSVER$
   IF Q$<"3.5" THEN
      BUTTON #18,"<<",5,140,15,15
      BUTTON #19,"<",21,140,15,15
      BUTTON #20,">",75,140,15,15
      BUTTON #21,">>",91,140,15,15
      BUTTON #22,"X",112,140,15,15
      BUTTON #23,"*",131,140,15,15
   ELSE
      IMAGEBUTTON #18,11,5,140,15,15
      IMAGEBUTTON #19,9,21,140,15,15
      IMAGEBUTTON #20,10,75,140,15,15
      IMAGEBUTTON #21,12,91,140,15,15
      IMAGEBUTTON #22,28,112,140,15,15
      IMAGEBUTTON #23,18,131,140,15,15
   ENDIF
   SETFONT 1
   BUTTON #24,"i",149,1,10,10
   SETFONT 0
   BUTTON #25,"abc",79,1,20,10
   BUTTON #26,"123",102,1,20,10
   BUTTON #27,"Int'l",125,1,20,10
RETURN

_ShowRecord:
   UPDATEFIELD #2,A$
   UPDATEFIELD #4,B$
   UPDATEFIELD #6,C$
   UPDATEFIELD #8,D$
   UPDATETEXT #10,E$
   UPDATEFIELD #13,F$
   J$=STR$(I,0)+"/"+STR$(K,0)
   UPDATELABEL #17,J$
   SETFOCUS #2
   GRAFFITISHIFT 1,150,150
RETURN

_RDate:
   IF E$="00/00/0000" THEN
      J$=DATESELECT$("")
   ELSE
      J$=DATESELECT$(E$)
   ENDIF
   IF J$<>"" THEN
      E$=J$
      UPDATETEXT #10,E$
   ENDIF
RETURN

BEGIN
IF R=0 THEN
   GOSUB _InitDisplay
   CHAIN "iBAddress2.ibas"
ELSE
   IF R=2 GOSUB _ShowRecord : R=1
ENDIF
WHILE D<>-2
   D=DOEVENTS
   IF D=10 GOSUB _RDate : D=0
   IF D=15 LET S=SELECTEDCHOICE
   IF D=24 LET D=MESSAGEBOX(Y$+Z$,1) : D=0
   IF D=25 KEYBOARD 0
   IF D=26 KEYBOARD 1
   IF D=27 KEYBOARD 2
   IF D<>0 CHAIN "iBAddress2.ibas"
WEND
SAVEPREF #1,L
SAVEPREF #2,K
SAVEPREF #3,I
SAVEPREF #4,S
SAVEPREF #5,T
END