3 || A simple
"Phone Book" BRexx program
4 || Just an example of
"guiutils.r" library usage
.
6 || 02/05/1999 by Generoso Martello
7 || generoso@martello
.com
8 || Catanzaro
Lido (ITALY
)
12 call load
'guiutils.r'
20 || Main program
... isn
't it very short ? :)
22 fr=0 ; op=0 ; ch='' ; call ansiSetCursor('OFF
')
25 call ansiColor('LIGHTCYAN
','BLACK
')
28 call ansiMenu 42,4,35,6,'Command List
'
29 call ansiColor('LIGHTCYAN
','BLUE
')
30 call ansiGoto 54,6 ; say ' A
= Add
'
31 call ansiGoto 54,7 ; say ' E
= Edit
'
32 call ansiGoto 54,8 ; say ' D
= Delete
'
33 call ansiGoto 54,9 ; say 'Enter
= View
'
34 call ansiGoto 54,10 ; say ' Esc
= Exit
'
36 call ansiColor('WHITE
','BLACK
')
38 call ansiGoto 13,1 ; say 'PHONE BOOK v
1.0'
39 call ansiGoto 11,2 ; say 'by Generoso Martello
'
40 call ansiGoto 42,14 ; say 'This is an example application which
'
41 call ansiGoto 42,15 ; say 'uses my
"guiutils.r" library
.'
42 call ansiGoto 42,17 ; say 'The library is supposed to work with
'
43 call ansiGoto 42,18 ; say 'the
32-bit DOS version of Brexx
.'
44 call ansiGoto 42,20 ; say 'Through this library you can
"dress"'
45 call ansiGoto 42,21 ; say 'your programs with colourful menus
,'
46 call ansiGoto 42,22 ; say 'lists
, input boxes
, requesters
...'
47 call ansiGoto 42,23 ; say '... Enjoy it
! :)'
49 ch=ansiList(2,4,35,19,fr,op,'Available Phone Books
','A
=Add
|E
=Edit
|D
=Delete
|Enter
=Open
|Esc
=Exit
','GUlist
','I
','')
51 op=subword(ch,1,1) ; fr=subword(ch,2,1) ; ch=subword(ch,3,1)
53 if ch=rxEnter & GUlist.count>0 then do
56 ch=ansiList(20,12,55,10,fr1,op1,'"'GUlist.op'" Phone Book
','A
=Add
|E
=Edit
|D
=Delete
|Enter
=View
|Esc
=Exit
','GUlist
.'op,'','')
57 op1=subword(ch,1,1) ; fr1=subword(ch,2,1) ; ch=subword(ch,3,1)
58 if ch='A
' | (ch='E
' & GUlist.op.count>0) then do
65 parse var GUlist.op.op1 name' ³
'phon' ³
'note
70 call ansiMenu 20,12,55,10,'Add
/Modify Record
- "'GUlist.op'"'
71 call ansiColor 'WHITE
','BLUE
'
72 call ansiGoto 22,15 ; say 'First Name and Last Name
'
73 call ansiGoto 22,17 ; say 'Telephone number
'
74 call ansiGoto 22,19 ; say 'Note
'
75 call ansiColor 'BLACK
','WHITE
'
76 call ansiOLine 22,16,53,' '
77 call ansiOLine 22,18,53,' '
78 call ansiOLine 22,20,53,' '
79 call ansiOLine 22,21,53,' '
80 call ansiGoto 22,16 ; say name'ee
'
81 call ansiGoto 22,18 ; say phon
82 call ansiGoto 22,20 ; say substr(note,1,52)
83 call ansiGoto 22,21 ; say substr(note,53)
85 name=ansiInputLine(22,16,1,0,25,name)
86 phon=ansiInputLine(22,18,1,0,25,phon)
87 note=ansiInputLine(22,20,2,0,52,note)
89 if strip(name)~='' then do
92 GUlist.op.cn=left(name,25)' ³
'left(phon,25)' ³
'note
95 else GUlist.op.op1=left(name,25)' ³
'left(phon,25)' ³
'note
97 /* BUBBLE SORT ... un po' di ordine
... :) */
98 ordinato
= 0 ; do
while ~ordinato
100 do curr
=0 for GUlist
.op
.count
-1
102 if GUlist
.op
.curr
> GUlist
.op
.next then do
104 GUlist
.op
.curr
=GUlist
.op
.next
113 else if ch
='D' & GUlist
.op
.count
>0 then do
114 if ansiRequest(32,14,30,"ARE YOU SURE ?","Delete this entry ?","Yes","No") then do
115 do x
=op1
+fr1
-1 for GUlist
.op
.count
117 GUlist
.op
.x
=GUlist
.op
.next
119 GUlist
.op
.count
=GUlist
.op
.count
-1
122 else if ch
=rxEnter
& GUlist
.op
.count
>0 then do
123 parse var GUlist
.op
.op1 name
' ³ 'phon
' ³ 'note
124 call ansiMenu
20,12,55,10,'Record Details - Hit any key to exit'
125 call ansiColor
'WHITE','BLUE'
126 call ansiGoto
22,15 ; say
'First Name and Last Name'
127 call ansiGoto
22,17 ; say
'Telephone number'
128 call ansiGoto
22,19 ; say
'Note'
129 call ansiColor
'BLACK','WHITE'
130 call ansiOLine
22,16,53,' '
131 call ansiOLine
22,18,53,' '
132 call ansiOLine
22,20,53,' '
133 call ansiOLine
22,21,53,' '
134 call ansiGoto
22,16 ; say name
135 call ansiGoto
22,18 ; say phon
136 call ansiGoto
22,20 ; say
substr(note
,1,52)
137 call ansiGoto
22,21 ; say
substr(note
,53)
143 else if ch
='A' | (ch
='E' & GUlist
.count
>0) then do
144 if ch
='A' then name
=''
146 call ansiMenu
20,12,32,5,'Add/Modify Phone Book'
147 call ansiColor
'WHITE','BLUE'
148 call ansiGoto
22,15 ; say
'Phone Book Name'
149 call ansiColor
'BLACK','WHITE'
150 name
=ansiInputLine(22,16,1,0,30,name
)
151 if strip(name
)~='' then do
154 GUlist
.cn
=name
; GUlist
.cn
.count
=0
160 else if ch
='D' & GUlist
.count
>0 then do
161 if ansiRequest(26,12,30,"ARE YOU SURE ?","Delete this section ?","Yes","No") then do
171 call ansiColor
'BLACK','BLACK'
172 call ansiBox
42,12,35,11
174 call ansiColor
'LIGHTRED','BLACK'
175 call ansiGoto
42,20 ; say
'Done! Press any key to exit.'
177 call
ansiColor('WHITE','BLACK') ; call ansiCls
178 call
ansiSetCursor("NORMAL")
182 || Loads my phonebook data
184 loadPhoneBook
: procedure expose GUlist
.
186 fd
=open('gudemo.dat','r')
190 if l
~='' then GUlist
.lc
=l
191 ic
=0 ; if ~eof(fd
) then l
=read(fd
)
192 do
while subword(l
,1,1)~='#' & ~eof(fd
)
193 GUlist
.lc
.ic
=l
; ic
=ic
+1
196 GUlist
.lc
.count
=ic
; lc
=lc
+1
197 if ~eof(fd
) then l
=read(fd
)
205 || Saves my phonebook data
207 savePhoneBook
: procedure expose GUlist
.
208 fd
=open('gudemo.dat','w')
210 call ansiMenu
14,11,56,6,'Updating Phone Book data...'
211 call ansiColor
'YELLOW','BLUE'
212 call ansiGoto
16,14 ; say
'Sections'
213 call ansiGoto
16,16 ; say
' Records'
214 do x
=0 for GUlist
.count
215 call ansiProgressBar
25,14,((x
+1)*100)/GUlist
.count
,38
216 if GUlist
.x
.flag
~='D' then do
217 call write fd
,GUlist
.x
,'nl'
218 do y
=0 for GUlist
.x
.count
219 call ansiProgressBar
25,16,((y
+1)*100)/GUlist
.x
.count
,38
220 call write fd
,GUlist
.x
.y
,'nl'
222 call write fd
,'#','nl'