home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / bcklib2.zip / EXAMPLEA.PRG < prev    next >
Text File  |  1993-01-16  |  5KB  |  134 lines

  1. /*
  2.     The source code contained within this file is protected under the
  3.     laws of the United States of America and by International Treaty.
  4.     Unless otherwise noted, the source contained herein is:
  5.  
  6.     Copyright (c)1990, 1991, 1992 BecknerVision Inc - All Rights Reserved
  7.  
  8.     Written by John Wm Beckner        THIS NOTICE MUST NOT BE REMOVED
  9.     BecknerVision Inc
  10.     PO Box 11945                      DISTRIBUTE ONLY WITH SHAREWARE
  11.     Winston-Salem NC 27116            VERSION OF THIS PRODUCT.
  12.     Fax: 919/760-1003
  13.  
  14. */
  15.  
  16. #include "beckner.inc"
  17.  
  18. LOCAL aNumbers := {1, 2, 3, 4, 5}, aChars := {"A", "B", "C", "D", "E"}
  19. LOCAL aMix := {"A", 2, "C", 3, "E"}
  20. LOCAL aNothing := {}, aNothingMore := {NIL, NIL, NIL}, cTemp, nTemp
  21.  
  22. FUNCTION ArrayTest()
  23.    CLS
  24.    ? "Test of Beckner Array Functions"
  25.    ?
  26.    ? "The following arrays are used in these tests:"
  27.    ?
  28.    ? "aNumbers     {1, 2, 3, 4, 5}"
  29.    ? [aChars       {"A", "B", "C", "D", "E"}]
  30.    ? [aMix         {"A", 2, "C", 4, "E"}]
  31.    ? "aNothing     {}"
  32.    ? "aNothingMore {NIL, NIL, NIL}"
  33.    ?
  34.    WAIT
  35.    CLS
  36.    ? "Average of {1,2,3,4,5} and {1,2,3}"
  37.    ? aAverage(aNumbers), aAverage(aNumbers, 1, 3)
  38.    ?
  39.    ? "Count of all elements in {1,2,3,4,5} and {1,2,3}"
  40.    ? aCount(aNumbers), aCount(aNumbers, , 1, 3)
  41.    ?
  42.    ? "Is aNothing empty?",if(aEmpty(aNothing), "Yes", "No")
  43.    ? "Is aMix empty?", if(aEmpty(aMix), "Yes", "No")
  44.    ? "Is aNothingMore empty?", if(aEmpty(aNothingMore), "Yes", "No")
  45.    ?
  46.    WAIT
  47.    CLS
  48.    ? "Creating a test file called TEST.DBF, which has the structure:"
  49.    ? "cNAME       Character   1"
  50.    ? "nBALANCE    Numeric     8  2"
  51.    ? "dDATE       Date"
  52.    fCreateDBF("TEST/cNAME/C/1/nBALANCE/N/8/2/dDATE/D")
  53.    fShare("Test")
  54.    ?
  55.    ? "Adding one record with the following data: "
  56.    fAddRecord()
  57.    ? "Name is   ", (Field->cName := "BECKNER")
  58.    ? "Balance is", (Field->nBalance := 100.00)
  59.    ? "Date is   ", (Field->dDate := date())
  60.    ?
  61.    ? "Using aFromRec() to create an array with the same data, as displayed:"
  62.    aFromRec(aNothing)
  63.    aEval(aNothing, {|xElement, nElNum| Qout(Field(nElNum), xElement)})
  64.    ?
  65.    vCursSave()
  66.    ACCEPT "Enter a new name for the first array element: " to cTemp
  67.    vCursRest()
  68.    ?
  69.    aNothing[1] := cTemp
  70.    ?
  71.    ? "Array element being stored into the second record"
  72.    fAddRecord()
  73.    aToRec(aNothing)
  74.    ? "The maximum element found in aNumbers is", aMax(aNumbers), "at element #"
  75.    ?? aMaxElement(aNumbers)
  76.    ? "The maximum element found in aChars is", aMax(aChars, "C"), "at element #"
  77.    ?? aMaxElement(aChars, "C")
  78.    ? "The minimum element found in aNumbers is", aMin(aNumbers), "at element #"
  79.    ?? aMinElement(aNumbers)
  80.    ? "The minimum element found in aChars is", aMin(aChars, "C"), "at element #"
  81.    ?? aMinElement(aChars, "C")
  82.    WAIT
  83.    CLS
  84.    ? "The length of aNothingMore prior to packing is", len(aNothingMore)
  85.    aPack(aNothingMore)
  86.    ? "The length of aNothingMore after packing is", len(aNothingMore)
  87.    ?
  88.    ? "Answer 'P' if you want to proceed with the aPrint test,"
  89.    vCursSave()
  90.    cTemp := "P"
  91.    ACCEPT "which requires your printer to be online: " to cTemp
  92.    vCursRest()
  93.    ?
  94.    IF cTemp$"Yy"
  95.       ?
  96.       ? "aNumbers is being printed, followed by aChars"
  97.       aPrint(aNumbers,,,,.n.)
  98.       aPrint(aChars)
  99.    ENDIF
  100.    ?
  101.    ? "A file is being created called TEST.TXT, which contents are:"
  102.    aWrite({"This is the first line", "and this is the second.",;
  103.    "Therefore, this is the last!"}, "TEST.TXT")
  104.    ? "Now the file is being read and displayed:"
  105.    aNothing := {}
  106.    aRead(aNothing, "TEST.TXT")
  107.    aEval(aNothing, {|cElement| qout(cElement)})
  108.    WAIT
  109.    CLS
  110.    ? "The sum of the elements in {1,2,3,4,5} and {1,2,3} are"
  111.    ? aSum(aNumbers), aSum(aNumbers, 1, 3)
  112.    ?
  113.    ? "The first number found in aMix is", aMatch(aMix, "N"), "at element #"
  114.    ?? aMatchNum(aMix, "N")
  115.    ? "The first character found in aMix is", aMatch(aMix, "C"), "at element #"
  116.    ?? aMatchNum(aMix, "C")
  117.    ?
  118.    ? "aChars as a single string using aArray2Char():"
  119.    ? (cTemp := aArray2Char(aChars))
  120.    ?
  121.    ? [The longest element in {"A", "ABC", "12"} is], aLongest({"A", "ABC", "12"})
  122.    ?? " characters"
  123.    ?
  124.    ? "The total of all string lengths in aChars is", aTotalLen(aChars)
  125.    ?
  126.    ? "Press any key to use the array pick list for aChars"
  127.    inkey(0)
  128.    CLS
  129.    nTemp := aPickList(aChars)
  130.    ? "You chose element #", nTemp
  131.    ?
  132.    ? "END OF ARRAY FUNCTIONS"
  133. ENDFUNCTION
  134.