Loading ...
Sorry, an error occurred while loading the content.

Phone Book V7

Expand Messages
  • green8819
    Continuing from my previous post... There are also people who are not proficient enough but cite something else for their mistakes. I may be interpreted as one
    Message 1 of 1 , Dec 12, 2012
    • 0 Attachment
      Continuing from my previous post...

      There are also people who are not proficient enough but cite something else for their mistakes. I may be interpreted as one of those. The earlier versions of this program did not run well in the 'LB variation' because of my erroneous coding all the while. I just discovered this, and have to say it out. If you don't understand all of the above, good!

      There is something wrong with the Sorting algorithm used in my previous versions. In this version, V7, I am using a slightly different but clearer method of Sorting.

      Please delete previous versions.

      '----code start
      'kill DefaultDir$ + "\phone.txt" :wait'for testing
      nomainwin

      'open datafile if not already existing
      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 'tot records
      wend
      close #1

      dim List$(tot,2),name$(tot),phon$(tot) 'will be tot+1 on update
      '
      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,"=")) 'words before the =
      List$(x,2)=trim$(word$(line$,2,"=")) 'words after the =
      wend
      close #1
      call pause 100

      sort List$(),1,tot,1

      for x=1 to tot
      name$(x)=List$(x,1) :phon$(x)=List$(x,2)
      next
      call pause 100
      for x=1 to 2:order$(x)="descend":next 'initialise sort order

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

      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.add, "Add New", [add], UL, 240,220,60,25
      Button #w.edit, "Edit Records", [edit], UL, 310,220,85,25
      Button #w.reStart, "ReStart", [reStart], UL, 402,220,55,25

      open "Phone Book v5" for dialog as #w 'for win?
      #w, "font Arial 10" :#w "trapclose [quit]"
      if tot=0 then
      #w.srch "!disable" :#w.nextFind "!disable" :#w.edit,"!disable"
      #w.nameSort "!disable" :#w.phonSort "!disable" :#w.unsel "!disable"
      end if
      #w.nameList,"singleclickselect" :#w.phonList,"singleclickselect"
      #w.nextFind "!disable"
      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 :#w.nameList, "reload" :#w.phonList, "reload"
      wait

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

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

      [unsel]
      'select nothing, remove highlight if any
      #w.nameList, "selectindex 0" :#w.phonList, "selectindex 0"
      wait

      [srch]
      #w.nameList, "selectindex 0" :#w.phonList, "selectindex 0"
      #w.srch "!disable" :#w.nextFind "!disable" :#w.add "!disable"
      #w.edit,"!disable" :#w.nameSort "!disable" :#w.phonSort "!disable"
      srch$=""
      prompt "Search what?";srch$
      srch$=lower$(srch$) 'remove or comment this for precise search
      if srch$="" then
      #w.srch "!enable" :#w.nextFind "!disable" :#w.add "!enable"
      #w.edit,"!enable" :#w.nameSort "!enable" :#w.phonSort "!enable"
      wait
      end if
      for x=1 to tot: content$=""
      content$=content$+List$(x,1)+List$(x,2)
      content$=lower$(content$) 'remove or comment this for precise search
      if instr(content$,srch$)=0 then [nextFind]
      #w.nameList,"select ";name$(x)''select+highlight name$(x)
      #w.phonList,"select ";phon$(x)
      #w.nextFind "!enable"
      wait
      [nextFind]
      next
      if srch$<>"" and x>tot then notice "No more found." :srch$=""
      if srch$<>"" and fnd$="" then notice "Not found." :srch$=""
      #w.nameList, "selectindex 0" :#w.phonList, "selectindex 0"
      #w.srch "!enable" :#w.nextFind "!disable" :#w.add "!enable"
      #w.edit,"!enable" :#w.nameSort "!enable" :#w.phonSort "!enable"
      #w.add "!setfocus"
      wait

      [add]
      #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.nameSort "!disable" :#w.phonSort "!disable"
      gosub [upDate]
      #w.nameList, "select ";name$ :#w.phonList, "select ";phon$
      #w.add "!enable"
      call pause 50
      #w.srch "!enable" :#w.add "!enable" :#w.phonSort "!enable"
      #w.edit,"!enable" :#w.nameSort "!enable"
      wait

      [edit]
      notice chr$(13)+_
      "If editing, follow the data format used."+chr$(13)+_
      "Don't forget to File>Save after making changes. "+_
      "Close notepad, press [ReStart]"
      run "notepad.exe phone.txt"
      wait

      [reStart]
      close #w
      goto [start]

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

      tot=tot+1 'to add 1 more rec
      if tot>1 then
      #w.nameSort "!enable" :#w.phonSort "!enable" :#w.edit,"!enable"
      end if
      dim List$(tot,2),name$(tot),phon$(tot) 'redim

      open "phone.txt" for append as #1 'add new rec at end of file
      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,"=")) 'create List$ array
      List$(x,2)=trim$(word$(line$,2,"="))
      next
      sort List$(),1,tot,1
      for x=1 to tot 'create other two arrays
      name$(x)=List$(x,1) :phon$(x)=List$(x,2)
      next
      close #1
      call pause 50

      sort List$(),1,tot,1

      open "phone.txt" for output as #1 'deletes old datafile, creates new
      for x=1 to tot
      line$=List$(x,1)+" = "+List$(x,2)
      print #1, line$ 'write to datafile, line by line
      next
      close #1

      'open again to carry on, else must run from start
      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
      #w.nameList "reload" :#w.phonList "reload"
      close #1
      call pause 50
      return
      '-----------------------------------------------------------------------
      sub pause msec
      timer msec, [off]
      wait
      [off]
      timer 0
      end sub
      '----code end
    Your message has been successfully submitted and would be delivered to recipients shortly.