home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / vdocs.zip / VC10A < prev    next >
Text File  |  1993-12-16  |  7KB  |  172 lines

  1. .TOPIC:                                            
  2. Number and Storage Handling
  3.  
  4.                                             VBBS 6.12 Documentation -- 10-A-1
  5.  
  6.  
  7.          ╔════════════════════════════════════════════════════════════════╗
  8.          ║  CHAPTER TEN ANNEX A     NUMBER AND STRING HANDLING            ║
  9.          ╚════════════════════════════════════════════════════════════════╝
  10.  
  11.  
  12.          NUMERIC OPERATORS
  13.          ═════════════════
  14.  
  15.                 VSCRIPT supports the following mathematical operators:
  16.  
  17.                        +  Addition           -  Subtraction
  18.                        *  Multiplication     /  Division
  19.                        ^  Exponentiation
  20.  
  21.          All math commands in the script language are performed from
  22.          left-to-right.  Parentheses can NOT be used in a formula, so
  23.          any math that needs to be done in a hierarchical format must be
  24.          done over more than one line.  Also, remember the restriction
  25.          on 'tokens' - a math symbol counts as a token, so only two math
  26.          operations can be performed on one line.
  27.  
  28.                    Example:                   Results:
  29.                    $a= 2 * 2 + 4              => 4 + 4       => 8
  30.                    $b = $a + 2 / 5            => 10 / 5      => 2
  31.                    $c = $b + 5 - 4            => 7 - 4       => 3
  32.                    $d = 4 / $b ^ 3            => 2 * 2 * 2   => 8
  33.  
  34.  
  35.          NUMERIC FUNCTIONS
  36.          ═════════════════
  37.  
  38.          INT 0 ->  <variable1> = <value2> INT 0
  39.  
  40.                This function takes the number stored in <value2> and
  41.            rounds down to the next lower whole number.  The resulting
  42.            integer is then stored in <variable1>.  Remember: negative
  43.            numbers also round down with this function as shown below:
  44.  
  45.                $total = -11.25 INT 0 returns a value of -12, not -11.
  46.  
  47.          SQR 0 ->  <variable1> = <value2> SQR 0
  48.  
  49.                This function returns the square root of the absolute
  50.            value of the number stored in <value2>.  The result is then
  51.            stored in <variable1>.  Note: The absolute value of a number
  52.            equals its positive value, ie absolute of -11 = 11.
  53.  
  54.          RND ->  <variable1> = <value1> RND <value2>
  55.  
  56.                This function generates a random number between the two
  57.            <value>'s.  If <value1> is smaller than <value2> then the
  58.            result will not include either number.  If <value1> is larger
  59.            than <value2> then the result can include either number.
  60.  
  61.  
  62.                                             VBBS 6.12 Documentation -- 10-A-2
  63.  
  64.  
  65.              Example:                Results:
  66.              $a = 4.15 * 4 + .25     => 16.85
  67.              $b = $a INT 0           => 16
  68.              $c = $b SQR 0           => 4
  69.              $d = $a INT 0 SQR 0     => 4
  70.              $e = $b RND $c          => a random number from 4 to 16
  71.              $f = $c RND $b          => a random number from 5 to 15
  72.  
  73.  
  74.          STRING OPERATORS
  75.          ════════════════
  76.  
  77.            & ->  <variable1> = <token3> & <token5> & <token7>
  78.  
  79.                This allows you to link together many variables and strings
  80.            to print as a single variable, effectively adding many tokens
  81.            together. ex: $Junk = "This is" & " one big " & "statement!"
  82.  
  83.  
  84.          STRING FUNCTIONS
  85.          ════════════════
  86.  
  87.                In addition to the '&' operators there are some functions
  88.            for use with strings and variables that store strings.
  89.  
  90.          ASC 0 ->  <variable1> = <string2> ASC 0
  91.  
  92.                This function finds the ASCII code of the first character
  93.            in <string2> and stores it in <variable1>.
  94.  
  95.          CHR 0 ->  <variable1> = <value2> CHR 0
  96.  
  97.                This function takes <value2> and places the character with
  98.            the matching ASCII code into <variable1>.
  99.  
  100.          LEN 0 ->  <variable1> = <string2> LEN 0
  101.  
  102.                This function returns the number of characters within
  103.            <string2> and places the result in <variable1>.
  104.  
  105.          UPPER 0 ->  <variable1> = <string2> UPPER 0
  106.  
  107.                This function returns the upper case equivalent of what is
  108.            in <string2>.  It only changes the lower case letters, leaving
  109.            all numbers and symbols as they are in the original <string2>.
  110.  
  111.          INSTR ->  <variable1> = <string2> INSTR <string3>
  112.  
  113.                This function scans <string2> to see if <string3> exists
  114.            within it.  It returns a 0 to <variable1) if it is not found,
  115.            otherwise it returns the position of <string3>.
  116.  
  117.  
  118.                                             VBBS 6.12 Documentation -- 10-A-3
  119.  
  120.  
  121.          MID   ->  <variable1> = <string2> MID <value3>
  122.          LEFT  ->  <variable1> = <string2> LEFT <value3>
  123.  
  124.                These functions return portions of a string. MID starts
  125.            at the character <value3> and returns the rest of the string.
  126.            LEFT starts at the left-most character and returns a number
  127.            of characters equal to <value3>.
  128.  
  129.            Example:                      Results:
  130.            $a = "aBc2" & "05 D" & "e╫Fg" => "aBc205 De╫Fg"
  131.            $b = $a MID 10                => ╫Fg
  132.            $c = $b ASC 0                 => 215 - the ASCII code for ╫
  133.            $d = $a LEFT 6 MID 4          => 205
  134.            $e = $d CHR 0                 => ═   - the ASCII 205 character
  135.            $f = $a INSTR "205"           => 4   - the 205 is in the string
  136.                                                   and the 2 is located in
  137.                                                   the 4th position.
  138.            $g = $a LEN 0                 => 12
  139.            $h = $a UPPER 0               => "ABC205 DE╫FG"
  140.  
  141.            Note: The quotes in the strings are not an actual part of the
  142.                  strings.  They are there only to denote the beginning
  143.                  and end of a single token.
  144.  
  145.  
  146.          STRING ALTERATIONS
  147.          ══════════════════
  148.  
  149.                There are a few commands that actually allow you to alter
  150.            the format of a variable.  All of them use the same syntax and
  151.            are described below.
  152.  
  153.          JC ->  JC <variable1> <value2>
  154.          JL ->  JL <variable1> <value2>
  155.          JR ->  JR <variable1> <value2>
  156.  
  157.                These commands all take what is stored within <variable1>
  158.            and pad it with extra spaces.  JC centers the <variable1> in
  159.            a field of <value2> spaces.  JL places it along the left margin
  160.            and JR places it on the right margin in a similar field.
  161.  
  162.            Example:                     Results:
  163.            $size = 14
  164.            $a = "Greed!"                => $a now has the value:
  165.            JC $a $size                     "    Greed!    "
  166.            $b = "Green!"                => $b now has the value:
  167.            JL $b $size                     "Green!        "
  168.            $c = "Groan!"                => $c now has the value:
  169.            JR $c $size                     "        Groan!"
  170.  
  171.  
  172.