home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-4.ZIP / HDR_EXMP.ZIP / EXAMPLES.ZIP / D4SIMPLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-31  |  2.2 KB  |  100 lines

  1.  
  2. #include "d4base.h"
  3. #include "w4.h"
  4.  
  5. static FIELD  fields[] =
  6. {
  7.    { "COMMENT", 'C', 40, 0, 0 },
  8.    { "A_VALUE", 'N',  8, 2, 0 },
  9.    { "B_VALUE", 'N',  8, 2, 0 },
  10.    { "SUM",     'N',  8, 2, 0 },
  11. } ;
  12.  
  13. /* It is good idea to declare field reference numbers globally. */
  14. long   a_value, b_value, sum ;
  15.  
  16. /* Declare some action routines. */
  17. static int  edit_database(void), list_database(void), compute_sums(void) ;
  18.  
  19. main()
  20. {
  21.    int  w_ref ;
  22.    char match_data[14] ;
  23.  
  24.    d4init() ;
  25.    w4clear( -1 ) ;
  26.    w4popup() ;  /* Make the default window a popup window. */
  27.  
  28.    /* Create the database if it does not yet exist. */
  29.    if ( u4file_first( "SIMPLE.DBF", match_data ) == 0 )
  30.       d4use( "SIMPLE" ) ;
  31.    else
  32.       d4create( "SIMPLE", 4, fields, 1 ) ;
  33.  
  34.    /* Assign the field reference numbers. */
  35.    a_value =  f4ref( "A_VALUE" ) ;
  36.    b_value =  f4ref( "B_VALUE" ) ;
  37.    sum     =  f4ref( "SUM" ) ;
  38.  
  39.    /* Define the menu window. */
  40.    w_ref =  w4define( -1,-1,-1,-1 ) ;
  41.    w4title( 0,-1, " Select Choice ", B_WHITE ) ;
  42.  
  43.    /* Specify the menu items. */
  44.    n4skip_over( n4(""), 1 ) ;
  45.    n4( "Edit Database" ) ;   n4action( edit_database ) ;
  46.    n4( "List Database" ) ;   n4action( list_database ) ;
  47.    n4( "Compute Sums"  ) ;   n4action( compute_sums  ) ;
  48.    n4skip_over( n4(""), 1 ) ;
  49.  
  50.    /* Calculate the window dimensions */
  51.    n4calc( w_ref, 9,31 ) ;
  52.  
  53.    /* Override the border specified by 'n4calc' */
  54.    w4border( DOUBLE_TOP, F_WHITE ) ;
  55.  
  56.    w4cursor( -1,-1 ) ;
  57.  
  58.    /* Activate the menu */
  59.    n4activate( &w_ref ) ;
  60.  
  61.    w4exit(0) ;
  62. }
  63.  
  64. edit_database()
  65. {
  66.    x4edit() ;
  67.    return 0 ;
  68. }
  69.  
  70. extern int  v4default_window ;
  71.  
  72. list_database()
  73. {
  74.    /* List to the default window which contains the entire screen. */
  75.    w4activate( v4default_window ) ;
  76.    x4list() ;
  77.    g4char() ;
  78.    w4deactivate( v4default_window ) ;
  79.    w4cursor( -1,-1 ) ;
  80.  
  81.    return 0 ;
  82. }
  83.  
  84. compute_sums()
  85. {
  86.    int     rc ;
  87.    double  result ;
  88.  
  89.    for ( rc = d4top(); rc != 3; rc = d4skip(1L) )
  90.    {
  91.       result =  f4value(a_value) + f4value(b_value) ;
  92.       f4replace( sum, &result ) ;
  93.       d4write( d4recno() ) ;
  94.    }
  95.  
  96.    w4display( " Message ", "Sum Computed", "", "Press a key", (char *) 0 ) ;
  97.  
  98.    return 0 ;
  99. }
  100.