home *** CD-ROM | disk | FTP | other *** search
/ Image Master / L80.iso / Net / websuite / websuite.exe / COUNTER.FG_ / COUNTER.FG
Encoding:
Text File  |  1997-12-08  |  1.7 KB  |  89 lines

  1. // Counter Class
  2. // (c) 1997 SmartDesk, Inc., All Rights Reserved
  3.  
  4.  
  5. FUNCTION CounterDisplay( filename, digits, dir )
  6.     local cntr
  7.     cntr = new( "counter", filename, dir )
  8.     if ( type( cntr ) != "O" )
  9.         return( "" )
  10.     end
  11.     cntr.increment( )
  12.     return( cntr.display( digits ) )
  13. END
  14.  
  15.  
  16. CLASS counter
  17.   PUBLIC:
  18.     local filename, value, imagedir
  19.         
  20.     METHOD new( filename, imagedir )
  21.         local hfile
  22.         _apGenerate( )
  23.         if ( type( imagedir ) != "C" )
  24.             ::imagedir = ""
  25.         else
  26.             ::imagedir = imagedir
  27.         end
  28.         
  29.         ::filename = filename
  30.         if ( ! fileExists( ::filename ) )
  31.             hfile = fileCreate( ::filename )
  32.             if ( hfile < 1 )
  33.                 errmsg( "CLASS counter", "Unable to create " + ::filename )
  34.                 return( 0 )
  35.             end
  36.             fwriteline( hfile, "[COUNTER]" )
  37.             fwriteline( hfile, "val=0" )
  38.             fclose( hfile )
  39.             
  40.             ::value = 0
  41.         else
  42.             ::value = 0 + iniGetString( ::filename, "COUNTER", "val", "0" )
  43.         end
  44.         
  45.         return( 1 )
  46.     END
  47.  
  48.  
  49.     METHOD increment( )
  50.         ::value++
  51.         iniSetString( ::filename, "COUNTER", "val", "" + ::value )
  52.         return( 1 )
  53.     END
  54.  
  55.  
  56.     METHOD display( digits )
  57.     
  58.         local str, valstr, i, image
  59.         
  60.         if ( ( type( digits ) != "N" ) || ( digits < 1 ) )
  61.             digits = 6
  62.         elseif ( digits > 8 )
  63.             digits = 8
  64.         end
  65.  
  66.         valstr = right( "00000000" + ::value, digits )
  67.         
  68.         str =  "<table border=0 colspacing=0 cellspacing=0>\r\n"
  69.         str += " <tr><td>\r\n"
  70.  
  71.         for ( i=1; i<=digits; i++ )
  72.  
  73.             image = "cntr" + substr( valstr, i, 1 ) + ".gif"
  74.             str += "<img src=\"" + ::imagedir + image + "\" border=0 width=15 height=20>"
  75.             
  76.         end
  77.         str += "\r\n"
  78.         str += " </td></tr>\r\n"
  79.         str += "</table>\r\n"
  80.     
  81.         return( str )
  82.     END
  83.     
  84. END
  85.  
  86.  
  87.  
  88.  
  89.