Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text bottom

DIGITAL%  PowerBASIC  Function

         

DIGITAL% function is a predicate (logical function evaluating to "true" or "false") that evaluates to "true" (-1), if its first parameter is digital, or to "false" (0), if its first parameters is not digital.  Second parameter specifies valid delimiters set of symbols that are ignored when string is tested for digital value.  Function can check for Decimal, Octal, Hexadecimal and Roman digital values.



 DIGITAL%  Source  Program                     Debugging program                     Debugging logout

      ' DIGITAL%(2.0)  Check Character String for Digital Value  04/28/1997-01/29/2010
      ' ------------------------------------------------------------------------------
      ' Copyright (C) 1997-2010 by Vladimir Veytsel                      www.davar.net

      ' Type -------------------------------------------------------------------------

      '    Function (predicate)

      ' Description ------------------------------------------------------------------

      '    DIGITAL% function is a predicate that returns digital characteristic
      '    of the specified string of possibly delimited digits.

      ' Parameters -------------------------------------------------------------------

      '    Strng$  - Character string to be checked for digital value
      '    Delim$  - Legal delimiters within digital string
      '              First character of the delimiter parameter may specify the
      '              type of the digital test to be performed, in which case it
      '              is considered to be a test type indicator (not a delimiter).
      '              "D" or "d"  - Check for Decimal digits ("0123456789")
      '              "O" or "o"  - Check for Octal   digits ("01234567")
      '              "H" or "h"  - Check for Hex     digits ("0123456789AaBbCcDdEeFf")
      '              "R" or "r"  - Check for Roman   digits ("IiVvXx")
      '              If the first character of the delimiter parameter is none
      '              of the above test type characters, it is considered to be
      '              a delimiter and test is performed for Decimal digits.

      ' Value ------------------------------------------------------------------------

      '    IF specified string is either EMPTY or entirely DIGITAL
      '       (with the exception of specified legal delimiters),
      '       THEN -1 (true)  is returned to the point of function invocation,
      '       ELSE  0 (false) is returned to the point of function invocation.

      ' Notes ------------------------------------------------------------------------

      '  - EMPTY string is considered to be DIGITAL in order to treat uniformly
      '    the default parameters.

      '    Roman digital test is formal - it checks that string consists only
      '    of "IiVvXx" characters plus whatever specified legitimate delimiters.
      '    Consistency of Roman numbers is NOT checked,
      '    E.g.:  Strings like "IIV" or "XIIII" are considered Roman-digital,
      '           thought they are clearly not Roman-numeric.

      ' Examples ---------------------------------------------------------------------

      '    DIGITAL%(""          ,"D"  )=-1
      '    DIGITAL%(""          ,".:/")=-1
      '    DIGITAL%("0123456789","d"  )=-1
      '    DIGITAL%("0123456789",".:/")=-1
      '    DIGITAL%("0.2.4.6.8" ,""   )= 0
      '    DIGITAL%("0.2.4.6.8" ,"."  )=-1
      '    DIGITAL%("0.2:4/6.8" ,""   )= 0
      '    DIGITAL%("0.2:4/6.8" ,".:/")=-1
      '    DIGITAL%("23456789"  ,"O"  )= 0
      '    DIGITAL%("01234567"  ,"o"  )=-1
      '    DIGITAL%("AbCdEfGh"  ,"H"  )= 0
      '    DIGITAL%("89AbCdEf"  ,"h"  )=-1
      '    DIGITAL%("IVX"       ,""   )= 0
      '    DIGITAL%("IVX"       ,"R"  )=-1
      '    DIGITAL%("I V X"     ,"R"  )= 0
      '    DIGITAL%("i v x"     ,"r " )=-1
      '    DIGITAL%("iivxiiii"  ,"r"  )=-1
      '    DIGITAL%(" IVX-12 "  ,"R- ")= 0

      ' Start Function ---------------------------------------------------------------

           FUNCTION DIGITAL%(Strng$,Delim$)

      ' Form and Return Function Value to the Point of Invocation --------------------

           SELECT CASE (UCASE$(LEFT$(Delim$,1)))
                  CASE ("D")
                       DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"0123456789")=0)
                  CASE ("O")
                       DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"01234567")=0)
                  CASE ("H")
                       DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"0123456789AaBbCcDdEeFf")=0)
                  CASE ("R")
                       DIGITAL%=(VERIFY(Strng$,MID$(Delim$,2)+"IiVvXx")=0)
                  CASE ELSE
                       DIGITAL%=(VERIFY(Strng$,Delim$+"0123456789")=0)
           END SELECT

      ' Finish Function --------------------------------------------------------------

           END FUNCTION
  
         

 DIGITAL%  Debugging  Program                     Source program                   Debugging logout

      ' DIGITAL%(2.0)  Check Char String for Digital Value   05/01/1997-01/04/2010
      ' --------------------------------------------------------------------------

        #INCLUDE "DIGITAL"

        FUNCTION PBMAIN

        PRINT "DIGITAL%(2.0)  Check Character String for Digital Value  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(74,"-")
        PRINT

        PRINT "DIGITAL%(''          ,'D'  )="; _
               DIGITAL%(""          ,"D"  )
        PRINT "DIGITAL%(''          ,'.:/')="; _
               DIGITAL%(""          ,".:/")
        PRINT "DIGITAL%('0123456789','d'  )="; _
               DIGITAL%("0123456789","d"  )
        PRINT "DIGITAL%('0123456789','.:/')="; _
               DIGITAL%("0123456789",".:/")
        PRINT "DIGITAL%('0.2.4.6.8' ,''   )="; _
               DIGITAL%("0.2.4.6.8" ,""   )
        PRINT "DIGITAL%('0.2.4.6.8' ,'.'  )="; _
               DIGITAL%("0.2.4.6.8" ,"."  )
        PRINT "DIGITAL%('0.2:4/6.8' ,''   )="; _
               DIGITAL%("0.2:4/6.8" ,""   )
        PRINT "DIGITAL%('0.2:4/6.8' ,'.:/')="; _
               DIGITAL%("0.2:4/6.8" ,".:/")
        PRINT "DIGITAL%('23456789'  ,'O'  )="; _
               DIGITAL%("23456789"  ,"O"  )
        PRINT "DIGITAL%('01234567'  ,'o'  )="; _
               DIGITAL%("01234567"  ,"o"  )
        PRINT "DIGITAL%('AbCdEfGh'  ,'H'  )="; _
               DIGITAL%("AbCdEfGh"  ,"H"  )
        PRINT "DIGITAL%('89AbCdEf'  ,'h'  )="; _
               DIGITAL%("89AbCdEf"  ,"h"  )
        PRINT "DIGITAL%('IVX'       ,''   )="; _
               DIGITAL%("IVX"       ,""   )
        PRINT "DIGITAL%('IVX'       ,'R'  )="; _
               DIGITAL%("IVX"       ,"R"  )
        PRINT "DIGITAL%('I V X'     ,'R'  )="; _
               DIGITAL%("I V X"     ,"R"  )
        PRINT "DIGITAL%('i v x'     ,'r ' )="; _
               DIGITAL%("i v x"     ,"r " )
        PRINT "DIGITAL%('iivxiiii'  ,'r'  )="; _
               DIGITAL%("iivxiiii"  ,"r"  )
        PRINT "DIGITAL%(' IVX-12 '  ,'R- ')="; _
               DIGITAL%(" IVX-12 "  ,"R- ")

        END FUNCTION
  
         

 DIGITAL%  Debugging  Logout                           Source program               Debugging program


   DIGITAL%(2.0)  Check Character String for Digital Value  01-29-2010  22:09
   --------------------------------------------------------------------------

   DIGITAL%(''          ,'D'  )=-1
   DIGITAL%(''          ,'.:/')=-1
   DIGITAL%('0123456789','d'  )=-1
   DIGITAL%('0123456789','.:/')=-1
   DIGITAL%('0.2.4.6.8' ,''   )= 0
   DIGITAL%('0.2.4.6.8' ,'.'  )=-1
   DIGITAL%('0.2:4/6.8' ,''   )= 0
   DIGITAL%('0.2:4/6.8' ,'.:/')=-1
   DIGITAL%('23456789'  ,'O'  )= 0
   DIGITAL%('01234567'  ,'o'  )=-1
   DIGITAL%('AbCdEfGh'  ,'H'  )= 0
   DIGITAL%('89AbCdEf'  ,'h'  )=-1
   DIGITAL%('IVX'       ,''   )= 0
   DIGITAL%('IVX'       ,'R'  )=-1
   DIGITAL%('I V X'     ,'R'  )= 0
   DIGITAL%('i v x'     ,'r ' )=-1
   DIGITAL%('iivxiiii'  ,'r'  )=-1
   DIGITAL%(' IVX-12 '  ,'R- ')= 0
        

         

View [and save] DIGITAL.BAS text       View [and save] ZDIGITAL.BAS text
(Use [Back] button or [Alt]+[CL] to return here from the viewed text)
Copyright © 19972010 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top