home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / p4w_all.zip / TI1437.ASC < prev    next >
Text File  |  1993-04-14  |  12KB  |  529 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  9.   VERSION  :  1.0
  10.        OS  :  WIN
  11.      DATE  :  April 14, 1993                           PAGE  :  1/8
  12.  
  13.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  14.  
  15.  
  16.  
  17.  
  18.   Intended Audience
  19.   All Paradox for Windows users
  20.  
  21.   Prerequisites
  22.   Familiarity with how to create calculated fields
  23.   Chapter 12, User's Guide, "Using Calculated Fields"
  24.   Chapter 3, ObjectPAL Reference Guide, "iif"
  25.  
  26.   Purpose of TI
  27.   This Technical Information sheet provides examples of using the
  28.   ObjectPAL Immediate If keyword, iif(), in calculated fields of
  29.   forms or reports.  Although the examples do not cover all
  30.   possible uses, they will provide you with techniques which you
  31.   could apply to your own applications.
  32.  
  33.  
  34.   When designing forms or reports, it is sometimes desirable to
  35.   place calculated fields containing conditional statements.  For
  36.   example, if the state is California multiply the Amount field by
  37.   10, otherwise multiply the Amount field by 5.  One of the
  38.   possible applications of the iif() keyword is to use it to
  39.   provide conditional functionality in calculated fields.  This
  40.   document provides detailed examples of how to use the iif()
  41.   keyword in calculated fields of forms and reports.  Several of
  42.   the examples, reference other ObjectPAL methods and procedures in
  43.   addition to the iif() keyword.  For a complete reference of
  44.   ObjectPAL methods, procedures, and keywords, refer to the
  45.   ObjectPAL Reference manual.
  46.  
  47.  
  48.   The syntax for the iif() keyword is:
  49.  
  50.        iif(Condition, ValueIfTrue, ValueIfFalse)
  51.  
  52.   where Condition is any expression that evaluates to a logical
  53.   value of True or False; ValueIfTrue is the value returned if
  54.   Condition evaluates to True; and ValueIfFalse is the value
  55.   returned if Condition evaluates to False.
  56.    
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  75.   VERSION  :  1.0
  76.        OS  :  WIN
  77.      DATE  :  April 14, 1993                           PAGE  :  2/8
  78.  
  79.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  80.  
  81.  
  82.  
  83.  
  84.   The first eight examples take you through a credit card payment
  85.   scenario using iif() keyword.  The sample Credit database has the
  86.   following structure and records:
  87.  
  88.   Credit │ Name │ Balance  │  Limit   │ Due Date │ Gender
  89.   ───────┼──────┼──────────┼──────────┼──────────┼───────
  90.          │ Bob  │ 1,100.00 │ 1,100.00 │ 12/2/91  │  M
  91.          │ Judy │   250.00 │ 3,000.00 │ 10/20/91 │  F
  92.          │ Mark │    12.00 │ 2,000.00 │ 6/12/92  │  m
  93.          │ Pam  │     0.00 │ 2,500.00 │          │  f
  94.  
  95.   NOTE: The Balance and Limit fields have a field type of $.
  96.  
  97.  
  98.   Example 1
  99.  
  100.   If a person has not yet reached their credit limit, indicate that
  101.   they still have credit available, otherwise indicate that no
  102.   credit remains:
  103.  
  104.   IIF([Credit.Balance]<[Credit.Limit], "Credit Available", "No
  105.   Credit Available")
  106.  
  107.   NOTE: The above expression must be entered on one line.
  108.  
  109.   Explanation of Example 1
  110.  
  111.   If the Balance is less than Limit, return "Credit Available",
  112.   otherwise return "No Credit Available".
  113.  
  114.   Result of Example 1
  115.  
  116.        Name      IIF() Result
  117.        ───────   ───────────────────
  118.        Bob       No Credit Available
  119.        Judy      Credit Available
  120.        Mark      Credit Available
  121.        Pam       Credit Available
  122.  
  123.   Notice that Bob is the only person who has used up his full
  124.   credit limit (Balance = 1100.00, Limit = 1100.00).
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  141.   VERSION  :  1.0
  142.        OS  :  WIN
  143.      DATE  :  April 14, 1993                           PAGE  :  3/8
  144.  
  145.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  146.  
  147.  
  148.  
  149.  
  150.   Example 2
  151.  
  152.   If there is a credit card balance, show a minimum payment due (2%
  153.   of the balance).  Otherwise, show zero since there is no
  154.   balance due:
  155.  
  156.   iif([Credit.Balance]>0, [Credit.Balance]*.02, 0)
  157.  
  158.   Explanation of Example 2
  159.  
  160.   If the Balance is greater than zero, return 2% of the Balance
  161.   value, otherwise return zero.
  162.  
  163.   Result of Example 2
  164.  
  165.        Name      IIF() Result
  166.        ──────    ────────────
  167.        Bob       22.00
  168.        Judy      5.00
  169.        Mark      .24
  170.        Pam       0
  171.  
  172.  
  173.   Example 3
  174.  
  175.   Paying 2% on any balance means that Mark would pay $0.24 and Judy
  176.   would pay $5.00.  In order to assure that a minimum payment of
  177.   $20 is received, the previous iif() expression could be modified
  178.   like this:
  179.  
  180.   iif([Credit.Balance]*.02<20, 20, [Credit.Balance]*.02)
  181.  
  182.   Explanation of Example 3
  183.  
  184.   If 2% of the balance is less than $20, require a payment of $20.
  185.   Otherwise, since the balance is high enough such that a 2%
  186.   payment is $20 or greater, require a 2% payment.
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  207.   VERSION  :  1.0
  208.        OS  :  WIN
  209.      DATE  :  April 14, 1993                           PAGE  :  4/8
  210.  
  211.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  212.  
  213.  
  214.  
  215.  
  216.   Result of Example 3
  217.  
  218.        Name      IIF() Result
  219.        ───────   ────────────
  220.        Bob       22.00
  221.        Judy      20
  222.        Mark      20
  223.        Pam       20
  224.  
  225.   Judy and Mark now pay a minimum of $20.
  226.  
  227.   NOTE: To format the output so that it looks like currency values,
  228.   refer to Example 5 in this Technical Information sheet.
  229.  
  230.  
  231.   Example 4
  232.  
  233.   But what about Mark?  He has a balance of $12.00.  The $20
  234.   minimum payment means he is expected to pay more than he owes.
  235.   And Pam has a zero balance--she does not owe anything!  The
  236.   previous iif() expression could be further modified so that
  237.   anyone with a balance less than $20 pays it in full:
  238.  
  239.   iif([Credit.Balance]<20,[Credit.Balance],
  240.   iif([Credit.Balance]*.02<20, 20, [Credit.Balance]*.02))
  241.  
  242.   NOTE: The above expression must be entered on one line.  Notice
  243.   how you can nest iif() keywords.
  244.  
  245.   Explanation of Example 4
  246.  
  247.   This nested iif() expression states that if the balance is less
  248.   than $20, the full balance is due.  Otherwise, the balance is $20
  249.   or greater.  So, if the balance is $20 or greater and 2% of this
  250.   balance is less than $20, $20 is due.  Otherwise, require a 2%
  251.   payment of the balance (since this 2% payment will be at least
  252.   $20).
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  273.   VERSION  :  1.0
  274.        OS  :  WIN
  275.      DATE  :  April 14, 1993                           PAGE  :  5/8
  276.  
  277.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  278.  
  279.  
  280.  
  281.  
  282.   Result of Example 4
  283.  
  284.        Name      IIF() Result
  285.        ───────   ────────────
  286.        Bob       22.00
  287.        Judy      20
  288.        Mark      12.00
  289.        Pam       0.00
  290.  
  291.   Now, Mark and Pam only pay what they owe.
  292.  
  293.  
  294.   Example 5:
  295.  
  296.   Finally, to format the output so that it looks like currency,
  297.   embed the iif() keyword within a format() procedure.
  298.  
  299.   format("W10.2, E$",
  300.   iif([Credit.Balance]<20, [Credit.Balance],
  301.   iif([Credit.Balance]*.02<20, 20, [Credit.Balance]*.02)))
  302.  
  303.   NOTE: The above expression must be entered on one line.
  304.  
  305.   The format() procedure allows you to format a string.  Its syntax
  306.   is format(FormatSpec, String).  For additional information on the
  307.   format() procedure, refer to Chapter 4 of the ObjectPAL Reference
  308.   manual.
  309.  
  310.   Explanation of Example 5
  311.  
  312.   Take the resulting value of the iif() keyword and format it as 10
  313.   digits with 2 decimal places, and use a floating dollar sign.
  314.  
  315.   Result of Example 5
  316.  
  317.        Name      IIF() Result
  318.        ───────   ────────────
  319.        Bob           $22.00
  320.        Judy          $20.00
  321.        Mark          $12.00
  322.        Pam            $0.00
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  339.   VERSION  :  1.0
  340.        OS  :  WIN
  341.      DATE  :  April 14, 1993                           PAGE  :  6/8
  342.  
  343.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  344.  
  345.  
  346.  
  347.  
  348.   Example 6
  349.  
  350.   Suppose you wanted to display the full gender of a cardholder
  351.   based on the Gender field (which contains "M" for male and "F"
  352.   for female).  In order to display "Male" or "Female" in a report
  353.   or form, you could use the following:
  354.  
  355.   iif([Credit.Gender]="M", "Male", "Female")
  356.  
  357.   Explanation of Example 6
  358.  
  359.   If Gender is "M", return "Male", otherwise return "Female."
  360.  
  361.   Result of Example 6
  362.  
  363.        Name      Gender    IIF() Result
  364.        ──────    ───────   ────────────
  365.        Bob       M         Male
  366.        Judy      F         Female
  367.        Mark      m         Female         <-----
  368.        Pam       f         Female
  369.  
  370.  
  371.   Example 7
  372.  
  373.   Notice that Mark's gender displayed as Female even though an "m"
  374.   was entered.  Since string comparisons are case-sensitive, "m" is
  375.   not equivalent to "M" and, therefore, returns "Female".  To
  376.   assure a proper comparison when Gender values are lower case,
  377.   use:
  378.  
  379.   iif(upper([Credit.Gender])="M", "Male", "Female")
  380.  
  381.   The upper() method allows you to change a string to upper-case.
  382.   Its syntax is upper(Expression).
  383.  
  384.   Explanation of Example 7
  385.  
  386.   Convert the Gender value to upper-case.  Then, if it equals "M",
  387.   return "Male", otherwise return "Female".
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  405.   VERSION  :  1.0
  406.        OS  :  WIN
  407.      DATE  :  April 14, 1993                           PAGE  :  7/8
  408.  
  409.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  410.  
  411.  
  412.  
  413.  
  414.   Result of Example 7
  415.  
  416.        Gender    IIF() Result
  417.        ───────   ────────────
  418.        M         Male
  419.        F         Female
  420.        m         Male
  421.        f         Female
  422.  
  423.   Since the upper() method converts "m" to "M", "Male" is returned
  424.   for both "M" and "m."
  425.  
  426.  
  427.   ┌──────────────────────────────────────────────────────────────┐
  428.   │    The next example no longer deals with the Credit table    │
  429.   └──────────────────────────────────────────────────────────────┘
  430.  
  431.  
  432.   Example 8
  433.  
  434.   Suppose you had an employee table which had a DOB field for Date
  435.   Of Birth.  You could use the following expression to see if today
  436.   was their birthday:
  437.  
  438.   iif(month([Employee.DOB])=month(today()) AND
  439.   day([Employee.DOB])=day(today()),
  440.   "Happy Birthday!", "")
  441.  
  442.   NOTE: The above expression must be entered on one line.
  443.  
  444.   The month() method returns the numeric month value of a date.
  445.   Its syntax is month(Date).  The day() method returns the numeric
  446.   day value of a date.  Its syntax is day(Date).  The today()
  447.   procedure returns the current date.
  448.  
  449.   Explanation of Example 8
  450.  
  451.   If the month value of the employee's date of birth is the same as
  452.   the current month and the day value of the employee's date of
  453.   birth is the same as the current day, then it is the employee's
  454.   birthday -- display message.  Otherwise, it is not the employee's
  455.   birthday -- do not display anything.
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.   PRODUCT  :  Paradox for Windows                   NUMBER  :  1437
  471.   VERSION  :  1.0
  472.        OS  :  WIN
  473.      DATE  :  April 14, 1993                           PAGE  :  8/8
  474.  
  475.     TITLE  :  How to Use IIF (Immediate If) in Calculated Fields
  476.  
  477.  
  478.  
  479.  
  480.   NOTE: Notice how you can use the "AND" operator to make a
  481.   compound condition.
  482.  
  483.   Result of Example 8
  484.  
  485.   Assume today is 7/4/90.
  486.  
  487.        Employee ID  DOB       IIF() Result
  488.        ───────────  ────────  ───────────────
  489.             1       7/4/62    Happy Birthday!
  490.             2       12/25/43
  491.             3       7/4/57    Happy Birthday!
  492.             4       1/1/70
  493.  
  494.  
  495.   To order other Technical Information sheets by fax, phone our
  496.   TechFax number at (800)822-4269.  A menu system will guide you
  497.   through ordering Technical Information sheets which will be faxed
  498.   directly to you.  You can even order a catalog which lists
  499.   articles you can request when calling the TechFax Number.
  500.  
  501.  
  502.   DISCLAIMER: You have the right to use this technical information
  503.   subject to the terms of the No-Nonsense License Statement that
  504.   you received with the Borland product to which this information
  505.   pertains.
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.