Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.

 
Module CheckDataType { 
      Module CheckThis {
            Class typeA {
            Private:
                  mval as currency 
            Public:
                  Property min {value}=-1
                  Property max {value}=0
                  Operator "++" {
                        if .mval=.[max] then Error "Number bigger than Max Value"
                        .mval++
                  }
                  Operator "--" {
                        if .mval=.[min] then Error "Number lower than Min Value"
                        .mval--
                  }
                  Operator "+=" (x){
                        if .mval>.[max]+x then Error "Number bigger than Max Value"
                        .mval+=x
                  }
                  Operator "-=" (x) {
                        if .mval<.[min]-x then Error "Number lower than Min Value"
                        .mval-=x
                  }
                  Value {
                    =.mval
                  }
                  Set (x) {
                        if x>.[max] then Error "Number bigger than Max Value"
                        if x<.[min] then Error "Number lower than Min Value"
                        .mval<=int(x)
                  }
            Class:
                  Module typeA (.[min], .[max]) {
                      .mval<=.[min]
                  }
            }
            K=typeA(1, 10)
            K=5
            Def TypeExp$(x)=Type$(x)
            Print Type$(K)="Group", TypeExp$(K)="Currency"
            K--
            Print K
            K=K+1
            Print K, K.Max, K.Min
            K+=4
            Print K, K.Max, K.Min
            Print -K*4=-36
            Try Ok {
                  K=400
            }
            If  Error or Not Ok then Print Error$
            \\ make a new K as K with name Z
            Z=Group(K)
            Print Z.Max, Z.Min, Z
            K++
            Z=Group(K)
            Print Z=K
            K-=5
            \\ We make M as pointer to K
            M->K
            Print Eval(M), K
            For M {This++}
            Print Eval(M), K
            For M {This=8}
            Print Eval(M), K
            Push Group(M), Group(M)
      }
      CheckThis
      \\ Read Group from stack of values and place a copy in each item in A()
      Dim A(4)=Group
      \\ We have one more group in stack, so we read it to new variable What
      \\ What isn't a pointer to object, is the object (internal is a pointer to objet but isn't usable for M2000)
      Read What 
      What++
      Print What.Max=10, What.Min=1, What=9  ' True True True
      Print A(2).Max=10, A(2).Min=1, A(2)=8 ' True True True
}
CheckDataType
 