  option SCALE, 96
  rem -- For comma delimited database --
  option FIELDSEP, ","

  dialog CREATE, "Mac's Rolodex",-1,-1,323,120
  dialog ADD,STYLE,BoldText,MS SanSerif,9,B
  dialog ADD,STYLE,Line_Style,Courier,,,BLACK
  dialog ADD,STYLE,List_Style,Courier,8

  dialog ADD,TEXT,Status,2,5,,,"Loading Data...",BoldText
  dialog ADD,COMBO,RoloList,0,127,192,,,LIST,CLICK,SORTED,List_Style

  dialog ADD,TEXT,Line1,26,5,314,1,"",Line_Style

  dialog ADD,TEXT,Name1Txt,36,5,,,"First Name"
  dialog ADD,EDIT,Name1,33,58,100

  dialog ADD,TEXT,Name2Txt,36,165,,,"Last Name"
  dialog ADD,EDIT,Name2,33,219,100

  dialog ADD,TEXT,AddressTxt,57,17,,,"Address"
  dialog ADD,EDIT,Address,54,58,261

  dialog ADD,TEXT,CityTxt,78,38,,,"City"
  dialog ADD,EDIT,City,75,58,122

  dialog ADD,TEXT,StateTxt,78,187,,,"State"
  dialog ADD,EDIT,State,75,215,30

  dialog ADD,TEXT,ZipTxt,78,256,,,"Zip"
  dialog ADD,EDIT,Zip,75,274,45

  dialog ADD,TEXT,PhoneTxt,99,24,,,"Phone"
  dialog ADD,EDIT,Phone,96,58,122

  dialog ADD,GROUP,Group1,95,187,133,22
  dialog ADD,BITBTN,New,97,189,40,18,,"New","Clear fields for new entry"
  dialog ADD,BITBTN,Save,97,230,40,18,,"Save","Save to database"
  dialog ADD,BITBTN,Delete,97,271,47,18,,"Delete","Remove from database"
  dialog SHOW

  rem -- Use as index var when editing existing file --
  %i = ""

  gosub Load_Database

:EVLOOP
  dialog SET, Status, Ready...
  wait EVENT
  goto @event()

:RoloListCLICK
  if @greater(@count(RoloList), 0)
    %i = @index(RoloList)
    parse "%a;%b;%c;%d;%e;%f;%g", @item(RoloList)
    dialog SET, Name2, %a
    dialog SET, Name1, %b
    dialog SET, Address, %c
    dialog SET, City, %d
    dialog SET, State, %e
    dialog SET, Zip, %f
    dialog SET, Phone, %g
  end 
  goto EVLOOP

:NewBUTTON
  gosub Clear_All
  goto EVLOOP

:SaveBUTTON
  if @dlgtext(Name2)
    dialog SET, Status, Saving Data...
    %s = @dlgtext(Name2)","@dlgtext(Name1)","@dlgtext(Address)","@dlgtext(City)","@dlgtext(State)","@dlgtext(Zip)","@dlgtext(Phone)
    if @greater(@count(RoloList), 0)
      rem -- Check if duplicate --
      list SEEK,RoloList, 0
      if @match(RoloList, %s)
        info Data Is Already Saved@tab()
      else 
        if %i
          rem -- Remove old entry first --
          gosub Delete_Item
        end 
        gosub Save_List
      end 
    else 
      rem -- If database is empty --
      gosub Save_List
    end 
  else 
    info Subject Must Have  'Last Name'  Entry@tab()
  end 
  goto EVLOOP

:DeleteBUTTON
  if %i
    if @ask(Delete This Subject?@tab())
      dialog SET, Status, Removing Data...
      gosub Delete_Item
      gosub Clear_All
      gosub Save_File
    end 
  else 
    info Subject Not Loaded From Database@tab()
  end 
  goto EVLOOP

:CLOSE
  exit 
  stop 

  rem --------------- GOSUB -------------------

:Delete_Item
  if @greater(@count(RoloList), 0)
    if %i
      list SEEK, RoloList, %i
      list DELETE, RoloList
    end 
  end 
  exit 

:Save_List
  list ADD, RoloList, %s
  rem -- Make sure it got into RoloList --
  if @greater(@count(RoloList), 0)
    list SEEK,RoloList, 0
    if @match(RoloList, %s)
      %i = @index(RoloList)
      gosub Save_File
    else 
      warn ERROR saving Data@tab()
    end 
  else 
    warn ERROR saving Data@tab()
  end 
  exit 

:Save_File
  list SAVEFILE, RoloList, rolodex.dat
  wait 
  exit 

:Clear_All
  rem -- Clear index var --
  %i = ""
  dialog CLEAR, Name1
  dialog CLEAR, Name2
  dialog CLEAR, Address
  dialog CLEAR, City
  dialog CLEAR, State
  dialog CLEAR, Zip
  dialog CLEAR, Phone
  dialog FOCUS, Name1
  exit 

:Load_Database
  if @file(rolodex.dat)
    list LOADFILE, RoloList, rolodex.dat
  else 
    rem -- You won't get this error after you save some data --
    info Cannot Find Database File:@cr()@cr()rolodex.dat
  end 
  dialog FOCUS, Name1
  exit 
