## Phone Book v8

Expand Messages
• With the Marys and Mikes problem solved. Tested for 100 name-phon pairs of data, with all pauses removed. Currently duplicate entries allowed, but can be
Message 1 of 1 , Dec 14 1:13 AM
With the 'Marys and Mikes' problem solved.
Tested for 100 name-phon pairs of data, with all pauses removed.
Currently duplicate entries allowed, but can be disallowed easily.
This series stops here. I did it as a sequel to one with more fields.
Please delete previous versions before using this version.

'----code start
nomainwin

open DefaultDir\$ + "\phone.txt" for append as #1
lenFile=lof(#1)
close #1
if lenFile=0 then [ShowWin]

[start]
tot=0
open "phone.txt" for input as #1
while eof(#1)=0 :line input #1, line\$ :tot=tot+1
wend
close #1

dim List\$(tot,2),name\$(tot),phon\$(tot)

x=0
open "phone.txt" for input as #1
while eof(#1)=0
x=x+1 :line input #1,line\$
List\$(x,1)=trim\$(word\$(line\$,1,"="))
List\$(x,2)=trim\$(word\$(line\$,2,"="))
wend
close #1

sort List\$(),1,tot,1

for x=1 to tot
name\$(x)=List\$(x,1) :phon\$(x)=List\$(x,2)
next
for x=1 to 2:order\$(x)="descend":next

[ShowWin]
WindowWidth = 475 :WindowHeight = 300
UpperLeftX=10 :UpperLeftY=10
Stylebits #w.nameList, 0,_CBS_DROPDOWN,0,0
Stylebits #w.phonList, 0,_CBS_DROPDOWN,0,0

statictext #w.st1, "", 440, 10, 30, 20
Button #w.1, "Name Sort", [w1], UL, 25, 30, 80, 20
Button #w.2, "Phone Sort",[w2], UL, 250, 30, 80, 20

Listbox #w.nameList, name\$(),[nameSelected],20, 55, 200, 150
Listbox #w.phonList, phon\$(),[phonSelected],245, 55, 200, 150

Button #w.srch, "Search", [srch], UL, 10,220,60,25
Button #w.nextFind, "Next Find", [nextFind], UL, 78,220,75,25
Button #w.unsel, "UnSelect", [unsel], UL, 160,220,70,25
Button #w.edit, "Edit Records", , UL, 310,220,85,25
Button #w.reStart, "ReStart", [reStart], UL, 402,220,55,25

open "Phone Book v7" for dialog as #w
#w, "font Arial 10" :#w "trapclose [quit]"
if tot=0 then
#w.srch "!disable" :#w.nextFind "!disable" :#w.edit,"!disable"
#w.1 "!disable" :#w.2 "!disable" :#w.unsel "!disable"
end if
#w.nameList,"singleclickselect" :#w.phonList,"singleclickselect"
#w.nextFind "!disable"
#w.st1 sel
wait

[w1]
btnnr=1 :goto [Sorts]
[w2]
btnnr=2
[Sorts]
select case order\$(btnnr)
case "ascend"
sort List\$(),1,tot,btnnr:order\$(btnnr)="descend"
case "descend"
sort List\$(),tot,1,btnnr:order\$(btnnr)="ascend"
end select
for x=1 to tot :name\$(x)=List\$(x,1) :phon\$(x)=List\$(x,2):next
'call pause 100
wait

[nameSelected]
#w.nameList, "selectionindex? sel"
#w.phonList, "select ";List\$(sel,2)
#w.st1 sel
wait

[phonSelected]
#w.phonList, "selectionindex? sel"
#w.nameList, "select ";List\$(sel,1)
#w.st1 sel
wait

[unsel]
#w.nameList, "selectindex 0" :#w.phonList, "selectindex 0"
#w.st1 sel
wait

[srch]
#w.nameList, "selectindex 0" :#w.phonList, "selectindex 0"
#w.srch "!disable" :#w.nextFind "!disable" :#w.add "!disable"
#w.edit,"!disable" :#w.1 "!disable" :#w.2 "!disable"
srch\$=""
prompt "Search what?";srch\$
srch\$=lower\$(srch\$)
if srch\$="" then
#w.srch "!enable" :#w.nextFind "!disable" :#w.add "!enable"
#w.edit,"!enable" :#w.1 "!enable" :#w.2 "!enable"
wait
end if
for x=1 to tot: content\$=""
content\$=List\$(x,1)+List\$(x,2)
content\$=lower\$(content\$)
if instr(content\$,srch\$)=0 then [nextFind]
#w.nameList,"selectindex ";x
#w.phonList,"selectindex ";x
#w.nextFind "!enable"
wait
[nextFind]
next
if srch\$<>"" and x>tot then notice "No more found." :srch\$=""
#w.nameList, "selectindex 0" :#w.phonList, "selectindex 0"
#w.srch "!enable" :#w.nextFind "!disable" :#w.add "!enable"
#w.edit,"!enable" :#w.1 "!enable" :#w.2 "!enable"
#w.st1 sel
wait

#w.nameList, "selectindex 0" :#w.phonList, "selectindex 0"
name\$="" :phon\$=""
prompt "Name?";name\$ :name\$=trim\$(name\$):if name\$="" then wait
prompt "Phone?";phon\$:phon\$=trim\$(phon\$):if phon\$="" then wait
#w.srch "!disable" :#w.nextFind "!disable" :#w.add "!disable"
#w.edit,"!disable" :#w.1 "!disable" :#w.2 "!disable"
gosub [upDate]
#w.st1 sel
#w.nameList, "select ";name\$ :#w.phonList, "select ";phon\$
#w.srch "!enable" :#w.add "!enable" :#w.2 "!enable"
#w.edit,"!enable" :#w.1 "!enable"
wait

notice chr\$(13)+_
"If editing, follow the data format used."+chr\$(13)+_
"Don't forget to File>Save after making changes. "+_
wait

[reStart]
close #w
goto [start]

[quit]
close #w
end
'========================================================================
[upDate]
tot=0
open "phone.txt" for input as #1
while eof(#1)=0
line input #1, line\$ :tot=tot+1
wend
close #1

tot=tot+1
if tot>1 then
#w.1 "!enable" :#w.2 "!enable" :#w.edit,"!enable"
end if
dim List\$(tot,2),name\$(tot),phon\$(tot)

open "phone.txt" for append as #1
print #1, name\$+" = "+phon\$
close #1

open "phone.txt" for input as #1
for x=1 to tot
line input #1, line\$
List\$(x,1)=trim\$(word\$(line\$,1,"="))
List\$(x,2)=trim\$(word\$(line\$,2,"="))
next
sort List\$(),1,tot,1
for x=1 to tot
name\$(x)=List\$(x,1) :phon\$(x)=List\$(x,2)
next
close #1

sort List\$(),1,tot,1

open "phone.txt" for output as #1
for x=1 to tot
line\$=List\$(x,1)+" = "+List\$(x,2)
print #1, line\$
next
close #1

open "phone.txt" for input as #1
for x=1 to tot
line input #1, line\$
List\$(x,1)=trim\$(word\$(line\$,1,"=")) :name\$(x)=List\$(x,1)
List\$(x,2)=trim\$(word\$(line\$,2,"=")) :phon\$(x)=List\$(x,2)
next