number range

POO ou Classe personnel

number range

Messagepar oguruma » 30 Jan 2005 à 12:50

merci son auteur

Code : Tout sélectionner
Public Class NumberRange
   ' A range of numerics.
   ' Please read the Gnu General Public License before use:
   ' http://www.gnu.org/licenses/gpl.txt
   ' @author Johan Känngård, http://dev.kanngard.net/
   ' @version 0.8a
   
   lo As Variant
   hi As Variant
   
   Public Sub new(lo As Variant, hi As Variant)
      ' Creates a new NumberRange from lo to hi.
      If Not ( Isscalar(lo) And Isscalar(hi) ) Then Error 2000, "Not scalars"
      If Not Typename(lo) = Typename(hi) Then Error 2000, "Not same type"
      If Not ( Isnumeric(lo) And Isnumeric(hi) ) Then Error 2000, "Not numerics"
      Me.lo = lo
      Me.hi = hi
   End Sub
   
   Public Function getMinimum() As Variant
      ' Returns the minimum number in this range.
      getMinimum = lo
   End Function
   
   Public Function getMaximum() As Variant
      ' Returns the maximum number in this range.
      getMaximum = hi
   End Function
   
   Public Function includesNumber(o As Variant) As Variant
      ' Tests whether the specified number occurs within this range.
      includesNumber = (o => lo And o =< hi)
   End Function
   
   Public Function includesRange(r As NumberRange) As Variant
      ' Tests whether the specified range occurs entirely within this range.
      includesRange = includesNumber(r.getMinimum()) _
      And includesNumber(r.getMaximum())
   End Function
   
   Public Function overlaps(r As NumberRange) As Variant
      ' Tests whether the specified range overlaps with this range.
      overlaps = includesNumber(r.getMinimum()) Or includesNumber(r.getMaximum())
   End Function
   
   Public Function toString() As String
      ' Returns the string representation of this range.
      toString = getMinimum() & " to " & getMaximum()
   End Function
End Class
Bien à vous

http://www.dominoarea.org/oguruma/

Les téléphones PORTABLES dans les TGV y en a MARRRE de ces voyageurs qui ne respectent pas les autres ! ARRET DES PORTABLES SVP - Merci

Fumeurs ! respectez les non fumeurs !!!
Fumeurs ! respectez la loi de février 2007 et les lieux publics !!! (ie. hall de gares)
Avatar de l’utilisateur
oguruma
Super V.I.P.
Super V.I.P.
 
Message(s) : 4086
Inscrit(e) le : 16 Déc 2004 à 08:50
Localisation : LILLE

Retour vers Programmation orienté objet