home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / phoneb.zip / PHONEBK.VRX < prev    next >
Text File  |  1995-03-14  |  23KB  |  822 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end; else do
  20.         call VROptions 'ImplicitNames'
  21.     end
  22.     InitArgs.0 = argCount
  23.     if( argCount > 0 )then do i = 1 to argCount
  24.         InitArgs.i = arg( i + argOff )
  25.     end
  26.     drop calledAs argCount argOff
  27.  
  28. /*  Load the windows
  29. */
  30.     call VRInit
  31.     parse source . . spec
  32.     _VREPrimaryWindowPath = ,
  33.         VRParseFileName( spec, "dpn" ) || ".VRW"
  34.     _VREPrimaryWindow = ,
  35.         VRLoad( parent, _VREPrimaryWindowPath )
  36.     drop parent spec
  37.     if( _VREPrimaryWindow == "" )then do
  38.         call VRMessage "", "Cannot load window:" VRError(), ,
  39.             "Error!"
  40.         _VREReturnValue = 32000
  41.         signal _VRELeaveMain
  42.     end
  43.  
  44. /*  Process events
  45. */
  46.     call Init
  47.     signal on halt
  48.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  49.         _VREEvent = VREvent()
  50.         interpret _VREEvent
  51.     end
  52. _VREHalt:
  53.     _VREReturnValue = Fini()
  54.     call VRDestroy _VREPrimaryWindow
  55. _VRELeaveMain:
  56.     call VRFini
  57. exit _VREReturnValue
  58.  
  59. VRLoadSecondary:
  60.     __vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 )
  61.     if __vrlsWait then do
  62.         call VRFlush
  63.     end
  64.     __vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) )
  65.     if __vrlsHWnd = '' then signal __vrlsDone
  66.     if __vrlsWait \= 1 then signal __vrlsDone
  67.     call VRSet __vrlsHWnd, 'WindowMode', 'Modal' 
  68.     __vrlsTmp = __vrlsWindows.0
  69.     if( DataType(__vrlsTmp) \= 'NUM' ) then do
  70.         __vrlsTmp = 1
  71.     end
  72.     else do
  73.         __vrlsTmp = __vrlsTmp + 1
  74.     end
  75.     __vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd )
  76.     __vrlsWindows.0 = __vrlsTmp
  77.     do while( VRIsValidObject( VRWindow() ) = 1 )
  78.         __vrlsEvent = VREvent()
  79.         interpret __vrlsEvent
  80.     end
  81.     __vrlsTmp = __vrlsWindows.0
  82.     __vrlsWindows.0 = __vrlsTmp - 1
  83.     call VRWindow __vrlsWindows.__vrlsTmp 
  84.     __vrlsHWnd = ''
  85. __vrlsDone:
  86. return __vrlsHWnd
  87.  
  88. /*:VRX         CN_People_ContextMenu
  89. */
  90. CN_People_ContextMenu: 
  91.     call VRMethod "MI_Popup","Popup"
  92. return
  93.  
  94. /*:VRX         CN_People_DoubleClick
  95. */
  96. CN_People_DoubleClick: 
  97.     container = "CN_People"
  98.  
  99.     /* get all selected records */
  100.     call VRMethod container, "GetRecordList", "Selected", "reclist."
  101.  
  102.     /* Get names of all the fields */
  103.     call VRMethod container, "GetFieldList", "FieldHandle."
  104.     do i=1 to FieldHandle.0
  105.       FieldName.i = VRMethod(container, "GetFieldAttr", FieldHandle.i, "Name")
  106.       fldname = FieldName.i
  107.       call value "FieldHandle.!"fldname, FieldHandle.i
  108.     end
  109.     FieldName.0 = FieldHandle.0
  110.  
  111.     /* loop through all selected records */    
  112.     do r=1 to reclist.0
  113.         call VRMethod container, "GetFieldData", reclist.r, "FieldData."
  114.  
  115.         /* build the text version of the record */
  116.         record = ""
  117.         do i = 1 to FieldName.0
  118.           record = record";"FieldName.i";"FieldData.i
  119.         end
  120.         record = ";"FieldData.!name";;;"||record
  121.     
  122.         /* open the notebook so user can edit the record */
  123.         record =  NoteBk( VRWindow(), record )
  124.         
  125.         parse var record ';' Name ';' icon ';' left ';' bottom ';' rem
  126.         call VRSet container, "Painting", 0
  127.         do while length(rem) > 0
  128.          parse var rem field ';' value ';' rem
  129.          ok = VRMethod( container, "SetFieldData", reclist.r, value("FieldHandle.!"field), value)
  130.         end 
  131.         call VRSet container, "Painting", 1
  132.     end
  133.  
  134.     /* turn off selection of container if container itself is currently selected */
  135.     call VRSet container, "Source", 0
  136.  
  137.  
  138. return
  139.  
  140. /*:VRX         CN_People_EndEdit
  141. */
  142. CN_People_EndEdit: 
  143. /***********************************************************************
  144.  *  This routine is needed under two circumstances:
  145.  *  1. when the user directly edits the caption of an icon (Icon view)
  146.  *     this routine sets the Name field to the same value *so it displays
  147.  *     the correct name on next switch to Detail view)
  148.  *  2. when the user directly edits the Name field (in Detail view)
  149.  *     this routine sets the caption to the same value (so it displays
  150.  *     the correct name on next switch to Icon view)
  151.  ***********************************************************************
  152.  */
  153.     container = "CN_People"
  154.     recordID = VRInfo("Record")
  155.     fieldID = VRInfo("Field")
  156.     recordID = VRInfo("Record")
  157.     cancelled = VRInfo("Cancelled")
  158.     
  159.     if cancelled then
  160.       return
  161.  
  162.     if fieldID = "" then                /* from experience this is the caption */
  163.      do
  164.         fldvalue = VRMethod(container,"GetRecordAttr",recordID,"Caption")
  165.         rc = VRMethod(container,"SetFieldData", recordID, "Name", fldvalue)
  166.         return
  167.      end
  168.  
  169.     /* Get names of all the fields */
  170.     call VRMethod container, "GetFieldList", "FieldHandle."
  171.     do i=1 to FieldHandle.0
  172.       fldname = VRMethod(container, "GetFieldAttr", FieldHandle.i, "Name")
  173.       FieldName.i = fldname
  174.       if FieldHandle.i = fieldID then
  175.        do
  176.         /* say fldname "changed" */
  177.         chgFieldName = fldname
  178.         if fldname = "Name" then
  179.          do
  180.           fldvalue = VRMethod(container, "GetFieldData", recordID, fieldID)
  181.           call VRMethod container, "SetRecordAttr", recordID, "Caption", fldvalue
  182.          end
  183.        end
  184.       call value "FieldHandle.!"fldname, FieldHandle.i
  185.     end
  186.     FieldName.0 = FieldHandle.0
  187.     
  188. return
  189.  
  190. /*:VRX         CN_People_Init
  191. */
  192. CN_People_Init: procedure expose Globals.
  193.     recordHandle = VRMethod( "CN_People", "AddField", "String", "Name",        "Name" )
  194.     recordHandle = VRMethod( "CN_People", "AddField", "String", "Company",     "Company" )
  195.     recordHandle = VRMethod( "CN_People", "AddField", "String", "Street",      "Street" )
  196.     recordHandle = VRMethod( "CN_People", "AddField", "String", "City",        "City" )
  197. /*    call VRMethod "CN_People", "SetFieldAttr", recordHandle, "Visible", 0  */
  198.     recordHandle = VRMethod( "CN_People", "AddField", "String", "State",       "State" )
  199.     recordHandle = VRMethod( "CN_People", "AddField", "String", "ZIPCode",     "ZIPCode" )
  200.     recordHandle = VRMethod( "CN_People", "AddField", "String", "Telephone",   "Telephone" )
  201.     recordHandle = VRMethod( "CN_People", "AddField", "String", "FAX",         "FAX" )
  202.     recordHandle = VRMethod( "CN_People", "AddField", "String", "Notes",       "Notes")
  203. return
  204.  
  205. /*:VRX         CN_People_Load
  206. */
  207. CN_People_Load: 
  208.   
  209.     /* Don't paint while we fill the container */
  210.     ok = VRSet( "CN_People", "Painting", 0 )
  211.  
  212.     if FileName = "" | FileName = "[New]" then
  213.       do
  214.         people.0 = 1
  215.         people.1 = ";John Doe;person.ico;;;Name;John Doe;Company;ABC Corp;Street;1 Main Street;City;Podunk;State;CA;Telephone;(415) 555-1212;Notes;"
  216.       end
  217.     else
  218.      do
  219.         do i=1 while lines(FileName)
  220.           rec = linein(FileName)
  221.           people.i = rec
  222.         end
  223.         people.0 = i-1
  224.         rc = stream(FileName,"C","CLOSE")
  225.      end  
  226.  
  227.     /* Fill the container */
  228.     ok = VRMethod( "CN_People", "AddRecordList", , "", "people.")
  229.  
  230.     /* Set default sort order */
  231.     ok = VRSet( "CN_People", "DetailSort", "Name" )
  232.  
  233.     /* Set to paint now */
  234.     ok = VRSet( "CN_People", "Painting", 1 )
  235.  
  236. return
  237.  
  238. /*:VRX         CN_People_PopupMenu
  239. */
  240. CN_People_PopupMenu: 
  241.     call VRMethod "M_Person", "Popup"
  242. return
  243.  
  244. /*:VRX         dialerDone
  245. */
  246. dialerDone: 
  247.     status = VRInfo("status")
  248.     /* say "Dialer sent status:" status */
  249. return
  250.  
  251. /*:VRX         Fini
  252. */
  253. Fini:
  254.     window = VRWindow()
  255.     call VRSet window, "Visible", 0
  256.     drop window
  257. return 0
  258.  
  259. /*:VRX         getINIKeys
  260. */
  261. getINIKeys: 
  262.  
  263.     AppName = "PhoneBook"       /* INI application name */
  264.     INIFile = "PHONEBK.INI"     /* INI file name */
  265.     COMPortKey = "COMPort"      /* INI key for comport */
  266.     BaudRateKey = "BaudRate"    /* INI key for baudrate */
  267.     DialStringKey = "DialString" /* INI key for dialing string */
  268.     HangupStringKey = "HangupString" /* INI key for hangup string */
  269.     LastFileKey = "LastFile"    /* INI key for last phonebook file used */
  270. return
  271.  
  272. /*:VRX         Halt
  273. */
  274. Halt:
  275.     signal _VREHalt
  276. return
  277.  
  278. /*:VRX         Init
  279. */
  280. Init:
  281.     call ReadINI
  282.     call setFileName FileName
  283.  
  284.     /* Make our main window active and visible */
  285.     window = VRWindow()
  286.     call VRMethod window, "CenterWindow"
  287.     call VRSet window, "Visible", 1
  288.     call VRMethod window, "Activate"
  289.     drop window
  290.  
  291.     call CN_People_Init         /* initialize the container window */
  292.  
  293.     call CN_People_Load         /* fille the container window */
  294.  
  295. return
  296.  
  297. /*:VRX         MainWindow_Close
  298. */
  299. MainWindow_Close:
  300.     call Quit
  301. return
  302.  
  303. /*:VRX         MainWindow_Resize
  304. */
  305. MainWindow_Resize: 
  306.     call VRSet "CN_People", "Painting", 0
  307.     call VRSet "CN_People", "Height", max(VRGet(VRWindow(),"Height")-939,0)
  308.     call VRSet "CN_People", "Width", max(VRGet(VRWindow(), "Width")-96,0)
  309.     call VRSet "CN_People", "Painting", 1
  310. return
  311.  
  312. /*:VRX         MI_File_Open_Click
  313. */
  314. MI_File_Open_Click: 
  315.     do forever
  316.         path = VRFileDialog( VRWindow(), "Open Phonebook", "Open", "*.PBK")
  317.         if path = "" then
  318.             return
  319.         RC = stream(path,"C","QUERY EXISTS")
  320.         if RC = "" then
  321.          do
  322.             msg.0 = 3
  323.             msg.1 = "Cannot find Phonebook file:"
  324.             msg.2 = path
  325.             msg.3 = "Press OK to continue."
  326.             button.0 = 1
  327.             button.1 = "OK"
  328.             call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
  329.          end
  330.         else
  331.           leave
  332.     end
  333.     
  334.     path = RC
  335.     do i=1 while lines(path)
  336.         line.i = linein(path)
  337.     end
  338.     line.0 = i
  339.    
  340.     call setFileName path
  341.     RC = stream(path,"C","CLOSE")
  342.     call WriteINI
  343.     
  344. return
  345.  
  346. /*:VRX         MI_File_Save_As_Click
  347. */
  348. MI_File_Save_As_Click: 
  349.  
  350.     do forever
  351.         path = VRFileDialog( VRWindow(), "Save Phonebook", "Save", "*.PBK")
  352.         if path = "" then
  353.             return
  354.         RC = stream(path,"C","QUERY EXISTS")
  355.         if RC \= "" then
  356.          do
  357.             msg.0 = 3
  358.             msg.1 = "Phonebook file already exists:"
  359.             msg.2 = path
  360.             msg.3 = "Press Yes to overwrite."
  361.             button.0 = 3
  362.             button.1 = "Yes"
  363.             button.2 = "No"
  364.             button.3 = "Cancel"
  365.             button = VRMessageStem( VRWindow(), "msg.","Error","N","button.",1,1)
  366.             if button = 1 then
  367.              leave
  368.          end
  369.         else
  370.           leave
  371.     end
  372.  
  373. /* path = RC */
  374.  
  375.  call saveFile path
  376.     
  377.  call setFileName path
  378.  call writeINI
  379. return
  380.  
  381. /*:VRX         MI_File_Save_Click
  382. */
  383. MI_File_Save_Click: 
  384.     if FileName = "" | FileName = "[New]" then
  385.         call MI_File_Save_As_Click
  386.     else
  387.      do
  388.         call saveFile FileName
  389.      end       
  390. return
  391.  
  392. /*:VRX         MI_Help_About_Click
  393. */
  394. MI_Help_About_Click: 
  395.     call ProdHelp VRWindow()
  396. return
  397.  
  398. /*:VRX         MI_Options_Click
  399. */
  400. MI_Options_Click: 
  401.     call Options VRWindow()
  402.     call WriteINI
  403. return
  404.  
  405. /*:VRX         MI_Popup_Delete_Click
  406. */
  407. MI_Popup_Delete_Click: 
  408.     container = VRInfo("Source")
  409.     call VRMethod container, "GetRecordList", "Source", "reclist."
  410.     do i=1 to reclist.0
  411.         call VRMethod "CN_People", "GetFieldData", reclist.i, "Fields."
  412.         call VRMethod "CN_People", "RemoveRecord", reclist.i       
  413.     end
  414.  
  415.     /* turn off selection of container if container itself is currently selected */
  416.     call VRSet container, "Source", 0
  417.  
  418. return
  419.  
  420. /*:VRX         MI_Popup_Dial_Click
  421. */
  422. MI_Popup_Dial_Click: 
  423.     container = VRInfo("Source")
  424.     call VRMethod container, "GetRecordList", "Source", "reclist."
  425.     if reclist.0 > 1 then
  426.      do
  427.         msg.0 = 3
  428.         msg.1 = "Cannot dial more than one person at a time."
  429.         msg.2 = "Select only one record to dial."
  430.         msg.3 = "Press OK to continue."
  431.         button.0 = 1
  432.         button.1 = "OK"
  433.         call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
  434.      end
  435.     if reclist.0 = 0 then
  436.      do
  437.         msg.0 = 3
  438.         msg.1 = "No person selected for dialing"
  439.         msg.2 = "Select one record to dial, then select Dial command."
  440.         msg.3 = "Press OK to continue."
  441.         button.0 = 1
  442.         button.1 = "OK"
  443.         call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
  444.      end
  445.  
  446.     do i=1 to reclist.0
  447.         call VRMethod "CN_People", "GetFieldData", reclist.i, "Fields."
  448.         
  449.         threadID = VRMethod("Application","StartThread","Dialer", Fields.!Telephone)
  450.         if threadID = -1 then
  451.          do
  452.           msg.0 = 3
  453.           msg.1 = "Could not start the dialer thread."
  454.           msg.2 = ""
  455.           msg.3 = "Press OK to continue."
  456.           button.0 = 1
  457.           button.1 = "OK"
  458.           call VRMessageStem VRWindow(), "msg.","Error","N","button.",1,1
  459.          end
  460.  
  461.         msg.0 = 3
  462.         msg.1 = "Dialing ..."
  463.         msg.2 = "Thread" threadID
  464.         msg.3 = "Press Cancel to abort dialing."
  465.         button.0 = 1
  466.         button.1 = "Cancel"
  467.         call VRMessageStem VRWindow(), "msg.","Dialing in progress","N","button.",1,1
  468.         call VRMethod "APplication","HaltThread",threadID
  469.        
  470.     end
  471.  
  472.     /* turn off selection of container if container itself is currently selected */
  473.     call VRSet container, "Source", 0
  474. return
  475. /*:VRX         MI_Popup_New_Click
  476. */
  477. MI_Popup_New_Click: 
  478.     retvalue = NoteBk( VRWindow(), "New" )
  479.     drop rec.
  480.     rec.0 = 1
  481.     rec.1 = retvalue
  482.     ok = VRMethod("CN_People","AddRecordList",,,"rec.")
  483. return
  484.  
  485. /*:VRX         MI_Popup_Open_Click
  486. */
  487. MI_Popup_Open_Click: 
  488.     container = VRInfo("Source")
  489.     call VRMethod container, "GetRecordList", "Source", "reclist."
  490.  
  491.     /* Get names of all the fields */
  492.     call VRMethod container, "GetFieldList", "FieldHandle."
  493.     do i=1 to FieldHandle.0
  494.       FieldName.i = VRMethod("CN_People", "GetFieldAttr", FieldHandle.i, "Name")
  495.     end
  496.     FieldName.0 = FieldHandle.0
  497.  
  498.     do r=1 to reclist.0
  499.         record = ""
  500.         call VRMethod "CN_People", "GetFieldData", reclist.r, "FieldData."
  501.         do i = 1 to FieldName.0
  502.           record = record";"FieldName.i";"FieldData.i
  503.         end
  504.         record = ";"FieldData.!name";;;"||record
  505.         record =  NoteBk( VRWindow(), record )
  506.         /* say "record = "record */
  507.     end
  508.  
  509.     /* turn off selection of container if container itself is currently selected */
  510.     call VRSet container, "Source", 0
  511.  
  512. return
  513.  
  514. /*:VRX         MI_Popup_Sort_By_City_Click
  515. */
  516. MI_Popup_Sort_By_City_Click: 
  517.      call MI_Sort_By "City"
  518.  
  519. return
  520.  
  521. /*:VRX         MI_Popup_Sort_By_Company_Click
  522. */
  523. MI_Popup_Sort_By_Company_Click: 
  524.      call MI_Sort_By "Company"
  525.  
  526. return
  527.  
  528. /*:VRX         MI_Popup_Sort_By_Name_Click
  529. */
  530. MI_Popup_Sort_By_Name_Click: 
  531.      call MI_Sort_By "Name"
  532.  
  533. return
  534.  
  535. /*:VRX         MI_Popup_Sort_By_State_Click
  536. */
  537. MI_Popup_Sort_By_State_Click: 
  538.      call MI_Sort_By "State"
  539.  
  540. return
  541.  
  542. /*:VRX         MI_Popup_Sort_By_Street_Click
  543. */
  544. MI_Popup_Sort_By_Street_Click: 
  545.      call MI_Sort_By "Street"
  546.  
  547. return
  548.  
  549. /*:VRX         MI_Popup_Sort_By_Telephone_Click
  550. */
  551. MI_Popup_Sort_By_Telephone_Click: 
  552.      call MI_Sort_By "Telephone"
  553.  
  554. return
  555.  
  556. /*:VRX         MI_Popup_Sort_By_ZIPCode_Click
  557. */
  558. MI_Popup_Sort_By_ZIPCode_Click: 
  559.      call MI_Sort_By "ZIPCode"
  560.  
  561. return
  562.  
  563. /*:VRX         MI_Popup_View_Detail_Click
  564. */
  565. MI_Popup_View_Detail_Click: 
  566.     call MI_View_As "Detail"
  567.  
  568. return
  569.  
  570. /*:VRX         MI_Popup_View_Icon_Click
  571. */
  572. MI_Popup_View_Icon_Click: 
  573.     call MI_View_As "Icon"
  574.     call VRMethod "CN_People","Arrange"
  575. return
  576.  
  577. /*:VRX         MI_Popup_View_Name_Click
  578. */
  579. MI_Popup_View_Name_Click: 
  580.     call MI_View_As "Name"
  581.  
  582. return
  583.  
  584. /*:VRX         MI_Popup_View_Text_Click
  585. */
  586. MI_Popup_View_Text_Click: 
  587.     call MI_View_As "Text"
  588.  
  589. return
  590.  
  591. /*:VRX         MI_Sort_By
  592. */
  593. MI_Sort_By: 
  594.     call VRSet "CN_People", "Sort", "Ascending"
  595.     call VRSet "CN_People", "DetailSort", arg(1)
  596.     call VRMethod "CN_People", "SortRecords"
  597.  
  598.     /* Uncheck all sort by menu items and check the one selected as arg(1) */
  599.     names = "Name Company Street City State ZIPCode Telephone"
  600.  
  601.     do n=1 to words(Names)
  602.      name = word(Names,n)
  603.      call VRSet "MI_Sort_By_"||name,"Checked",arg(1) = name
  604.      call VRSet "MI_Popup_Sort_By_"||name, "Checked", arg(1) = name
  605.     end
  606.     
  607. return
  608.  
  609. /*:VRX         MI_Sort_By_City_Click
  610. */
  611. MI_Sort_By_City_Click: 
  612.     call MI_Sort_By "City"
  613. return
  614.  
  615. /*:VRX         MI_Sort_By_Company_Click
  616. */
  617. MI_Sort_By_Company_Click: 
  618.      call MI_Sort_By "Company"
  619. return
  620.  
  621. /*:VRX         MI_Sort_By_Name_Click
  622. */
  623. MI_Sort_By_Name_Click: 
  624.     call MI_Sort_By "Name"
  625. return
  626.  
  627. /*:VRX         MI_Sort_By_State_Click
  628. */
  629. MI_Sort_By_State_Click: 
  630.     call MI_Sort_By "State"
  631. return
  632.  
  633. /*:VRX         MI_Sort_By_Street_Click
  634. */
  635. MI_Sort_By_Street_Click: 
  636.     call MI_Sort_By "Street"
  637. return
  638.  
  639. /*:VRX         MI_Sort_By_Telephone_Click
  640. */
  641. MI_Sort_By_Telephone_Click: 
  642.     call MI_Sort_By "Telephone"
  643. return
  644.  
  645. /*:VRX         MI_Sort_By_ZIPCode_Click
  646. */
  647. MI_Sort_By_ZIPCode_Click: 
  648.     call MI_Sort_By "ZIPCode"
  649. return
  650.  
  651. /*:VRX         MI_View_arrange_Click
  652. */
  653. MI_View_Arrange_Click: 
  654.     call VRMethod "CN_People","Arrange"
  655.  
  656. return
  657.  
  658. /*:VRX         MI_View_As
  659. */
  660. MI_View_As: 
  661.     /* Set the View of the container as requested by arg(1) */
  662.     Call VRSet "CN_People","View",arg(1)
  663.  
  664.     /* Uncheck all View menu items and check the one selected as arg(1) */
  665.     names = "Icon Name Text Detail"
  666.  
  667.     do n=1 to words(Names)
  668.      name = word(Names,n)
  669.      call VRSet "MI_View_"||name,"Checked",arg(1) = name
  670.      call VRSet "MI_Popup_View_"||name,"Checked", arg(1) = name
  671.     end
  672.  
  673. return
  674.  
  675. /*:VRX         MI_View_Detail_Click
  676. */
  677. MI_View_Detail_Click: 
  678.     call MI_View_As "Detail"
  679. return
  680.  
  681. /*:VRX         MI_View_Icon_Click
  682. */
  683. MI_View_Icon_Click: 
  684.     call MI_View_As "Icon"
  685.     call VRMethod "CN_People","Arrange"
  686. return
  687.  
  688. /*:VRX         MI_View_Name_Click
  689. */
  690. MI_View_Name_Click: 
  691.     call MI_View_As "Name"
  692. return
  693.  
  694. /*:VRX         MI_View_Text_Click
  695. */
  696. MI_View_Text_Click: 
  697.     call MI_View_As "Text"
  698. return
  699.  
  700. /*:VRX         Quit
  701. */
  702. Quit:
  703.     window = VRWindow()
  704.     call VRSet window, "Shutdown", 1
  705.     drop window
  706. return
  707.  
  708. /*:VRX         ReadINI
  709. */
  710. ReadINI: 
  711. /************************************************************************    
  712.  *   Get values from INI file - PHONEBK.INI or create it if necessary
  713.  ************************************************************************
  714.  */    
  715.     call getINIkeys
  716.  
  717.     COMPort = VRGetIni( AppName, COMPortKey, INIFile, "NoClose" )
  718.     if COMPort = "" then
  719.      do
  720.        COMPort = "COM1:"   
  721.        BaudRate = "2400"
  722.        DialString = "ATDT"
  723.        HangupString = "ATH"
  724.        FileName = "PHONEBK.PBK"
  725.        ok = VRSetIni(AppName, COMPortKey, COMPort, INIFile, "NoClose")
  726.        ok = VRSetIni(AppName, BaudRateKey, BaudRate, INIFile, "NoClose")
  727.        ok = VRSetIni(AppName, DialStringKey, DialString, INIFile, "NoClose")
  728.        ok = VRSetIni(AppName, HangupStringKey, HangupString, INIFile, "NoClose")
  729.  
  730.        ok = VRSetIni(AppName, LastFileKey, FileName, INIFile)
  731.      end
  732.     else
  733.      do
  734.         BaudRate = VRGetIni( AppName, BaudRateKey, INIFile, "NoClose")
  735.         DialString = VRGetIni( AppName, DialStringKey, INIFile, "NoClose")
  736.         HangupString = VRGetIni( AppName, HangupStringKey, INIFile, "NoClose")
  737.         FileName = VRGetIni( AppName, LastFileKey, INIFile)
  738.      end
  739.  
  740.     /* Set global variables so other files can get to them */
  741.     call VRMethod "Application", "PutVar", "COMPort"
  742.     call VRMethod "Application", "PutVar", "BaudRate"
  743.     call VRMethod "Application", "PutVar", "DialString"
  744.     call VRMethod "Application", "PutVar", "HangupString"
  745.     call VRMethod "Application", "PutVar", "FileName"
  746.  
  747. return
  748.  
  749. /*:VRX         saveFile
  750. */
  751. saveFile: 
  752.     
  753.     path = arg(1)
  754.  
  755.     RC = stream(path,"C", "QUERY EXISTS")
  756.     if RC \= "" then
  757.       "@del" path                            /* Delete old file */
  758.  
  759.     container = "CN_People"
  760.  
  761.     /* Get names of all the fields */
  762.     call VRMethod container, "GetFieldList", "FieldHandle."
  763.     do i=1 to FieldHandle.0
  764.       FieldName.i = VRMethod("CN_People", "GetFieldAttr", FieldHandle.i, "Name")
  765.     end
  766.     FieldName.0 = FieldHandle.0
  767.  
  768.     /* get all the records */
  769.     call VRMethod container, "GetRecordList", "All", "rec."
  770.  
  771.     /* loop to write each record */    
  772.     do r=1 to rec.0
  773.       record = ""
  774.       call VRMethod container, "GetFieldData", rec.r, "FieldData."
  775.        do i = 1 to FieldName.0
  776.           record = record";"FieldName.i";"FieldData.i
  777.        end
  778.        left = VRMethod( container, "GetRecordAttr", rec.r, "Left")
  779.        bottom = VRMethod( container, "GetRecordAttr", rec.r, "Bottom")
  780.        icon = VRMethod( container, "GetRecordAttr", rec.r, "Icon")
  781.        record = ";"FieldData.!name";"icon";"left";"bottom||record
  782.         /* say "record = "record  */
  783.       ok = lineout(path,record)
  784.     end
  785.  
  786.     RC = stream(path,"C","CLOSE")
  787. return
  788.  
  789. /*:VRX         setFileName
  790. */
  791. setFileName: 
  792.     FileName = arg(1)
  793.     call VRSet "MainWindow", "Caption", "Phone Book -" FileName
  794. return
  795.  
  796. /*:VRX         WriteINI
  797. */
  798. WriteINI: 
  799. /************************************************************************
  800.  *   Save values in INI file - PHONEBK.INI or create it if necessary
  801.  ************************************************************************
  802.  */    
  803.  
  804.     call getINIkeys
  805.     /* Get global variables values */
  806.     call VRMethod "Application", "GetVar", "COMPort"
  807.     call VRMethod "Application", "GetVar", "BaudRate"
  808.     call VRMethod "Application", "GetVar", "DialString"
  809.     call VRMethod "Application", "GetVar", "HangupString"
  810.     call VRMethod "Application", "GetVar", "FileName"
  811.     /* say COMport BaudRate DialString HangupString FileName */
  812.  
  813.     ok = VRSetIni(AppName, COMPortKey, COMPort, INIFile, "NoClose")
  814.     ok = VRSetIni(AppName, BaudRateKey, BaudRate, INIFile, "NoClose")
  815.     ok = VRSetIni(AppName, DialStringKey, DialString, INIFile, "NoClose")
  816.     ok = VRSetIni(AppName, HangupStringKey, HangupString, INIFile, "NoClose")
  817.  
  818.     ok = VRSetIni(AppName, LastFileKey, FileName, INIFile)
  819.  
  820. return
  821.  
  822.